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