Skip to content

Commit d140c77

Browse files
committed
support vector of char
1 parent 36b201d commit d140c77

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/rendering.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Render `str` into `img` using the font `face` of size `pixelsize` at coordinates
4343
* `valign`: :vtop, :vcenter, :vbaseline, or :vbottom
4444
"""
4545
function renderstring!(
46-
img::AbstractMatrix{T}, str::String, face::FTFont, pixelsize::Union{Int, Tuple{Int, Int}}, y0, x0;
46+
img::AbstractMatrix{T}, str::Union{AbstractVector{Char},String}, face::FTFont, pixelsize::Union{Int, Tuple{Int, Int}}, y0, x0;
4747
fcolor::Union{AbstractVector{T},T} = one_or_typemax(T), bcolor::Union{T,Nothing} = zero(T),
4848
halign::Symbol = :hleft, valign::Symbol = :vbaseline
4949
) where T<:Union{Real,Colorant}
@@ -53,6 +53,8 @@ function renderstring!(
5353
pixelsize = pixelsize[1]
5454
end
5555

56+
str = str isa AbstractVector ? String(str) : str
57+
5658
set_pixelsize(face, pixelsize)
5759

5860
bitmaps = Vector{Matrix{UInt8}}(undef, lastindex(str))
@@ -103,11 +105,7 @@ function renderstring!(
103105
px += kx
104106
end
105107

106-
fcol = if fcolor isa AbstractVector
107-
fcolor[istr]
108-
else
109-
fcolor
110-
end
108+
fcol = fcolor isa AbstractVector ? fcolor[istr] : fcolor
111109

112110
# trim parts of glyph images that are outside the destination
113111
cliprowlo, cliprowhi = max(0, -(py-by)), max(0, py - by + h - imgh)

test/runtests.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ renderstring!(
168168
valign = :vcenter,
169169
)
170170
renderstring!(zeros(UInt8, 20, 100), "helgo", face, 10, 25, 80)
171-
let fcolor = map(x->RGB{Float32}(x...), [(.1, .2, .3), (.5, .2, .25), (.6, .3, .1), (.2, .5, .6), (.7, .1, .9)])
172-
renderstring!(zeros(RGB{Float32}, 20, 100), "helgo", face, 10, 25, 80; fcolor = fcolor)
171+
for str in ("helgo", collect("helgo"))
172+
fcolor = [RGB{Float32}(rand(3)...) for _ 1:length(str)]
173+
renderstring!(zeros(RGB{Float32}, 20, 100), str, face, 10, 0, 0; fcolor = fcolor)
173174
end
174175

175176
# Find fonts

0 commit comments

Comments
 (0)