@@ -38,13 +38,16 @@ Render `str` into `img` using the font `face` of size `pixelsize` at coordinates
38
38
# Arguments
39
39
* `y0,x0`: origin is in upper left with positive `y` going down
40
40
* `fcolor`: foreground color; AbstractVector{T}, typemax(T) for T<:Integer, otherwise one(T)
41
- * `bcolor`: background color; set to `nothing` for transparent
41
+ * `gcolor`: background color; AbstractVector{T}, typemax(T) for T<:Integer, otherwise one(T)
42
+ * `bcolor`: canvas background color; set to `nothing` for transparent
42
43
* `halign`: :hleft, :hcenter, or :hright
43
44
* `valign`: :vtop, :vcenter, :vbaseline, or :vbottom
44
45
"""
45
46
function renderstring! (
46
47
img:: AbstractMatrix{T} , str:: Union{AbstractVector{Char},String} , face:: FTFont , pixelsize:: Union{Int, Tuple{Int, Int}} , y0, x0;
47
- fcolor:: Union{AbstractVector{T},T} = one_or_typemax (T), bcolor:: Union{T,Nothing} = zero (T),
48
+ fcolor:: Union{AbstractVector{T},T} = one_or_typemax (T),
49
+ gcolor:: Union{AbstractVector{T},T,Nothing} = nothing ,
50
+ bcolor:: Union{T,Nothing} = zero (T),
48
51
halign:: Symbol = :hleft , valign:: Symbol = :vbaseline
49
52
) where T<: Union{Real,Colorant}
50
53
@@ -106,23 +109,28 @@ function renderstring!(
106
109
end
107
110
108
111
fcol = fcolor isa AbstractVector ? fcolor[istr] : fcolor
112
+ gcol = gcolor isa AbstractVector ? gcolor[istr] : gcolor
109
113
110
114
# trim parts of glyph images that are outside the destination
111
115
cliprowlo, cliprowhi = max (0 , - (py- by)), max (0 , py - by + h - imgh)
112
116
clipcollo, clipcolhi = max (0 , - bx- px), max (0 , px + bx + w - imgw)
113
117
114
- if bcolor === nothing
118
+ if gcol === nothing
115
119
for row = 1 + cliprowlo : h- cliprowhi, col = 1 + clipcollo : w- clipcolhi
116
- bitmaps[istr][col,row]== 0 && continue
120
+ bitmaps[istr][col,row] == 0 && continue
117
121
c1 = bitmaps[istr][col,row] / bitmapmax * fcol
118
122
img[row+ py- by, col+ px+ bx] = T <: Integer ? round (T, c1) : T (c1)
119
123
end
120
124
else
125
+ img[
126
+ clamp (py- ymax+ 1 , 1 , imgh) : clamp (py- ymin- 1 , 1 , imgh),
127
+ clamp (px- 1 , 1 , imgw) : clamp (px+ sumadvancex- 1 , 1 , imgw)
128
+ ] .= gcol
121
129
for row = 1 + cliprowlo : h- cliprowhi, col = 1 + clipcollo : w- clipcolhi
122
130
bitmaps[istr][col, row] == 0 && continue
123
131
w1 = bitmaps[istr][col, row] / bitmapmax
124
132
c1 = w1 * fcol
125
- c0 = (1.0 - w1) * bcolor
133
+ c0 = (1.0 - w1) * gcol
126
134
img[row + py - by, col + px + bx] = T <: Integer ? round (T, c1 + c0) : T (c1 + c0)
127
135
end
128
136
end
0 commit comments