@@ -2,90 +2,109 @@ using LaTeXStrings
22import MathTeXEngine:
33 generate_tex_elements, inkwidth, inkheight, bottominkbound, TeXChar, HLine
44
5+ # function text3D(str::LaTeXString, anchor::Point3D;
6+ # halign=:left,
7+ # valign=:baseline,
8+ # about=Point3D(0., 0., 0.),
9+ # rotation::Rotation=RotXYZ(0, 0, 0))
10+ #
11+ # # this is just a hacked version of the Luxor code
12+ #
13+ # # Function from MathTexEngine
14+ # sentence = generate_tex_elements(str)
15+ #
16+ # # Get current font size.
17+ # font_size = get_fontsize()
18+ #
19+ # textw, texth = latextextsize(str)
20+ # bottom_pt, top_pt = rawlatexboundingbox(str)
21+ #
22+ # translate_x, translate_y = Luxor.texalign(halign, valign, bottom_pt, top_pt, font_size)
23+ #
24+ # pt = project(anchor)
25+ #
26+ # rotationfixed=true
27+ # # Writes text using ModernCMU font.
28+ # for text in sentence
29+ # if isnothing(pt)
30+ # continue
31+ # end
32+ # @layer begin
33+ # translate(pt)
34+ # if !rotationfixed
35+ # #rotate(angle) ?
36+ # translate(translate_x, translate_y)
37+ # else
38+ # l_pt, r_pt = Luxor.latexboundingbox(str, halign = halign, valign = valign)
39+ # translate((l_pt + r_pt)/2)
40+ # #rotate(angle) ?
41+ # translate(Point(translate_x, translate_y) - (l_pt + r_pt)/2)
42+ # end
43+ # if text[1] isa TeXChar
44+ # fontface(text[1].font.family_name)
45+ # fontsize(font_size * text[3])
46+ #
47+ # textoutlines(string(text[1].char), Point(text[2]...) * font_size * (1, -1), :path,
48+ # halign=halign,
49+ # valign=valign,
50+ # startnewpath=true)
51+ # o = getpathflat()
52+ # newpath() # otherwise the path would be drawn twice
53+ # for e in o
54+ # if e.element_type == 0
55+ # (x, y) = e.points
56+ # newpt = rotateby(Point3D(anchor.x + x, anchor.y -y, anchor.z), about, rotation)
57+ # pin(newpt, gfunction = (p3, p2) -> move(p2))
58+ # elseif e.element_type == 1
59+ # (x, y) = e.points
60+ # newpt = rotateby(Point3D(anchor.x + x, anchor.y -y, anchor.z), about, rotation)
61+ # pin(newpt, gfunction = (p3, p2) -> line(p2))
62+ # elseif e.element_type == 3
63+ # closepath()
64+ # else
65+ # error("unknown path element " * repr(e.element_type) * repr(e.points))
66+ # end
67+ # end
68+ # fillpath()
69+ #
70+ # elseif text[1] isa HLine
71+ # pointstart = Point(text[2]...) * font_size * (1, -1)
72+ # pointend = pointstart + Point(text[1].width, 0) * font_size
73+ #
74+ # newstartpt = rotateby(Point3D(anchor.x + pointstart.x, anchor.y - pointstart.y, anchor.z), about, rotation)
75+ # newendpt = rotateby(Point3D(anchor.x + pointend.x, anchor.y - pointend.y, anchor.z), about, rotation)
76+ #
77+ # pin(newstartpt, newendpt)
78+ # end
79+ # end
80+ # end
81+ # end
82+
83+ # try this version using Paths
584
685"""
7- text3D(str::LaTeXString, anchor::Point3D;
86+ text3D(str::LaTeXString, anchor::Point3D;
887 halign=:left,
988 valign=:baseline,
1089 about=Point3D(0., 0., 0.),
11- rotation::Rotation=RotXYZ(0, 0, 0))
90+ rotation::Rotation=RotXYZ(0, 0, 0),
91+ portion = 1.0,
92+ steps = 20,
93+ startnewpath=true,
94+ action=:fill)
1295
1396Like `text3D()` but draws LaTeX strings.
1497"""
1598function text3D (str:: LaTeXString , anchor:: Point3D ;
1699 halign= :left ,
17100 valign= :baseline ,
18101 about= Point3D (0. , 0. , 0. ),
19- rotation:: Rotation = RotXYZ (0 , 0 , 0 ))
20-
21- # this is just a hacked version of the Luxor code
22-
23- # Function from MathTexEngine
24- sentence = generate_tex_elements (str)
25-
26- # Get current font size.
27- font_size = get_fontsize ()
28-
29- textw, texth = latextextsize (str)
30- bottom_pt, top_pt = rawlatexboundingbox (str)
31-
32- translate_x, translate_y = Luxor. texalign (halign, valign, bottom_pt, top_pt, font_size)
33-
34- pt = project (anchor)
35-
36- rotationfixed= true
37- # Writes text using ModernCMU font.
38- for text in sentence
39- if isnothing (pt)
40- continue
41- end
42- @layer begin
43- translate (pt)
44- if ! rotationfixed
45- # rotate(angle) ?
46- translate (translate_x, translate_y)
47- else
48- l_pt, r_pt = Luxor. latexboundingbox (str, halign = halign, valign = valign)
49- translate ((l_pt + r_pt)/ 2 )
50- # rotate(angle) ?
51- translate (Point (translate_x, translate_y) - (l_pt + r_pt)/ 2 )
52- end
53- if text[1 ] isa TeXChar
54- fontface (text[1 ]. font. family_name)
55- fontsize (font_size * text[3 ])
56- # Luxor.text(string(text[1].char), Point(text[2]...) * font_size * (1, -1))
57- textoutlines (string (text[1 ]. char), Point (text[2 ]. .. ) * font_size * (1 , - 1 ), :path ,
58- halign= halign,
59- valign= valign,
60- startnewpath= true )
61- o = getpathflat ()
62- newpath () # otherwise the path would be drawn twice
63- for e in o
64- if e. element_type == 0
65- (x, y) = e. points
66- newpt = rotateby (Point3D (anchor. x + x, anchor. y - y, anchor. z), about, rotation)
67- pin (newpt, gfunction = (p3, p2) -> move (p2))
68- elseif e. element_type == 1
69- (x, y) = e. points
70- newpt = rotateby (Point3D (anchor. x + x, anchor. y - y, anchor. z), about, rotation)
71- pin (newpt, gfunction = (p3, p2) -> line (p2))
72- elseif e. element_type == 3
73- closepath ()
74- else
75- error (" unknown path element " * repr (e. element_type) * repr (e. points))
76- end
77- end
78- fillpath ()
79-
80- elseif text[1 ] isa HLine
81- pointstart = Point (text[2 ]. .. ) * font_size * (1 , - 1 )
82- pointend = pointstart + Point (text[1 ]. width, 0 ) * font_size
83-
84- newstartpt = rotateby (Point3D (anchor. x + pointstart. x, anchor. y - pointstart. y, anchor. z), about, rotation)
85- newendpt = rotateby (Point3D (anchor. x + pointend. x, anchor. y - pointend. y, anchor. z), about, rotation)
86-
87- pin (newstartpt, newendpt)
88- end
89- end
90- end
102+ rotation:: Rotation = RotXYZ (0 , 0 , 0 ),
103+ portion = 1.0 ,
104+ steps = 20 ,
105+ startnewpath= true ,
106+ action= :fill )
107+ text (str, paths= true , halign= halign, valign= valign) # angle? rotationfixed?
108+ latexpath = storepath ()
109+ drawpath (latexpath, portion, anchor, action= action, startnewpath= startnewpath, about= about, rotation= rotation, steps= steps)
91110end
0 commit comments