@@ -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
- 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),
46
+ 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
48
halign:: Symbol = :hleft , valign:: Symbol = :vbaseline
49
49
) where T<: Union{Real,Colorant}
50
50
@@ -53,6 +53,8 @@ function renderstring!(
53
53
pixelsize = pixelsize[1 ]
54
54
end
55
55
56
+ str = str isa AbstractVector ? String (str) : str
57
+
56
58
set_pixelsize (face, pixelsize)
57
59
58
60
bitmaps = Vector {Matrix{UInt8}} (undef, lastindex (str))
@@ -103,21 +105,23 @@ function renderstring!(
103
105
px += kx
104
106
end
105
107
108
+ fcol = fcolor isa AbstractVector ? fcolor[istr] : fcolor
109
+
106
110
# trim parts of glyph images that are outside the destination
107
111
cliprowlo, cliprowhi = max (0 , - (py- by)), max (0 , py - by + h - imgh)
108
112
clipcollo, clipcolhi = max (0 , - bx- px), max (0 , px + bx + w - imgw)
109
113
110
114
if bcolor === nothing
111
115
for row = 1 + cliprowlo : h- cliprowhi, col = 1 + clipcollo : w- clipcolhi
112
116
bitmaps[istr][col,row]== 0 && continue
113
- c1 = bitmaps[istr][col,row] / bitmapmax * fcolor
117
+ c1 = bitmaps[istr][col,row] / bitmapmax * fcol
114
118
img[row+ py- by, col+ px+ bx] = T <: Integer ? round (T, c1) : T (c1)
115
119
end
116
120
else
117
121
for row = 1 + cliprowlo : h- cliprowhi, col = 1 + clipcollo : w- clipcolhi
118
122
bitmaps[istr][col, row] == 0 && continue
119
123
w1 = bitmaps[istr][col, row] / bitmapmax
120
- c1 = w1 * fcolor
124
+ c1 = w1 * fcol
121
125
c0 = (1.0 - w1) * bcolor
122
126
img[row + py - by, col + px + bx] = T <: Integer ? round (T, c1 + c0) : T (c1 + c0)
123
127
end
0 commit comments