Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
StyledTextImager.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
5namespace Stroika::Frameworks::Led {
6
7 /*
8 ********************************************************************************
9 ********************************* StyleRunElement ******************************
10 ********************************************************************************
11 */
12 inline StyleRunElement::StyleRunElement (StyleMarker* marker, size_t length)
13 : fMarker{marker}
14 , fLength{length}
15 {
16 }
17
18 /*
19 ********************************************************************************
20 ******************* SimpleStyleMarkerByFontSpec<BASECLASS> *********************
21 ********************************************************************************
22 */
23#if qStroika_Frameworks_Led_SupportGDI
24 template <class BASECLASS>
25 FontSpecification SimpleStyleMarkerByFontSpec<BASECLASS>::MakeFontSpec (const StyledTextImager* imager, const StyleRunElement& /*runElement*/) const
26 {
27 RequireNotNull (imager);
28 return imager->GetDefaultFont ();
29 }
30 template <class BASECLASS>
31 void SimpleStyleMarkerByFontSpec<BASECLASS>::DrawSegment (const StyledTextImager* imager, const StyleRunElement& runElement, Tablet* tablet,
32 size_t from, size_t to, const TextLayoutBlock& text, const Led_Rect& drawInto,
33 const Led_Rect& /*invalidRect*/, CoordinateType useBaseLine, DistanceType* pixelsDrawn)
34 {
35 RequireNotNull (imager);
36 imager->DrawSegment_ (tablet, MakeFontSpec (imager, runElement), from, to, text, drawInto, useBaseLine, pixelsDrawn);
37 }
38 template <class BASECLASS>
39 void SimpleStyleMarkerByFontSpec<BASECLASS>::MeasureSegmentWidth (const StyledTextImager* imager, const StyleRunElement& runElement, size_t from,
40 size_t to, const Led_tChar* text, DistanceType* distanceResults) const
41 {
42 RequireNotNull (imager);
43 imager->MeasureSegmentWidth_ (this->MakeFontSpec (imager, runElement), from, to, text, distanceResults);
44 }
45 template <class BASECLASS>
46 DistanceType SimpleStyleMarkerByFontSpec<BASECLASS>::MeasureSegmentHeight (const StyledTextImager* imager,
47 const StyleRunElement& runElement, size_t from, size_t to) const
48 {
49 RequireNotNull (imager);
50 return (imager->MeasureSegmentHeight_ (this->MakeFontSpec (imager, runElement), from, to));
51 }
52 template <class BASECLASS>
53 DistanceType SimpleStyleMarkerByFontSpec<BASECLASS>::MeasureSegmentBaseLine (const StyledTextImager* imager,
54 const StyleRunElement& runElement, size_t from, size_t to) const
55 {
56 RequireNotNull (imager);
57 return (imager->MeasureSegmentBaseLine_ (this->MakeFontSpec (imager, runElement), from, to));
58 }
59#endif
60
61 /*
62 ********************************************************************************
63 ************* SimpleStyleMarkerByIncrementalFontSpec<BASECLASS> ****************
64 ********************************************************************************
65 */
66 template <class BASECLASS>
67 inline SimpleStyleMarkerByIncrementalFontSpec<BASECLASS>::SimpleStyleMarkerByIncrementalFontSpec (const IncrementalFontSpecification& styleInfo)
68 : fFontSpecification{styleInfo}
69 {
70 }
71#if qStroika_Frameworks_Led_SupportGDI
72 template <class BASECLASS>
73 FontSpecification SimpleStyleMarkerByIncrementalFontSpec<BASECLASS>::MakeFontSpec (const StyledTextImager* imager, const StyleRunElement& runElement) const
74 {
75 RequireNotNull (imager);
76 FontSpecification fsp = inherited::MakeFontSpec (imager, runElement);
77 fsp.MergeIn (fFontSpecification);
78 return fsp;
79 }
80#endif
81
82 /*
83 ********************************************************************************
84 *************************** TrivialFontSpecStyleMarker *************************
85 ********************************************************************************
86 */
87 inline TrivialFontSpecStyleMarker::TrivialFontSpecStyleMarker (const IncrementalFontSpecification& styleInfo)
88 : inherited{styleInfo}
89 {
90 }
91
92 /*
93 ********************************************************************************
94 ********************** SimpleStyleMarkerWithExtraDraw<BASECLASS> ***************
95 ********************************************************************************
96 */
97 template <class BASECLASS>
98 StyleRunElement SimpleStyleMarkerWithExtraDraw<BASECLASS>::MungeRunElement (const StyleRunElement& inRunElt) const
99 {
100 StyleRunElement newRunElement = inRunElt;
101 Require (inRunElt.fMarker == (StyleMarker*)this);
102 newRunElement.fMarker = nullptr;
103 for (auto i = newRunElement.fSupercededMarkers.begin (); i != newRunElement.fSupercededMarkers.end ();) {
104 if (newRunElement.fMarker == nullptr or newRunElement.fMarker->GetPriority () < (*i)->GetPriority ()) {
105 newRunElement.fMarker = (*i);
106 i = newRunElement.fSupercededMarkers.erase (i);
107 }
108 else {
109 ++i;
110 }
111 }
112 return newRunElement;
113 }
114#if qStroika_Frameworks_Led_SupportGDI
115 template <class BASECLASS>
116 void SimpleStyleMarkerWithExtraDraw<BASECLASS>::DrawSegment (const StyledTextImager* imager, const StyleRunElement& runElement, Tablet* tablet,
117 size_t from, size_t to, const TextLayoutBlock& text, const Led_Rect& drawInto,
118 const Led_Rect& invalidRect, CoordinateType useBaseLine, DistanceType* pixelsDrawn)
119 {
120 RequireNotNull (imager);
121 AssertNotNull (pixelsDrawn); // if allowed to pass nullptr - I must pass my own value so I can pass along to DrawExtra - see if anyone does this - LGP 2000-07-08
122
123 StyleRunElement re = MungeRunElement (runElement);
124 if (re.fMarker == nullptr) {
125 imager->DrawSegment_ (tablet, this->MakeFontSpec (imager, re), from, to, text, drawInto, useBaseLine, pixelsDrawn);
126 }
127 else {
128 re.fMarker->DrawSegment (imager, re, tablet, from, to, text, drawInto, invalidRect, useBaseLine, pixelsDrawn);
129 }
130 DrawExtra (imager, re, tablet, from, to, text, drawInto, useBaseLine, *pixelsDrawn);
131 }
132 template <class BASECLASS>
133 void SimpleStyleMarkerWithExtraDraw<BASECLASS>::MeasureSegmentWidth (const StyledTextImager* imager, const StyleRunElement& runElement, size_t from,
134 size_t to, const Led_tChar* text, DistanceType* distanceResults) const
135 {
136 RequireNotNull (imager);
137 StyleRunElement re = MungeRunElement (runElement);
138 if (re.fMarker == nullptr) {
139 imager->MeasureSegmentWidth_ (this->MakeFontSpec (imager, re), from, to, text, distanceResults);
140 }
141 else {
142 re.fMarker->MeasureSegmentWidth (imager, re, from, to, text, distanceResults);
143 }
144 }
145 template <class BASECLASS>
146 DistanceType SimpleStyleMarkerWithExtraDraw<BASECLASS>::MeasureSegmentHeight (const StyledTextImager* imager,
147 const StyleRunElement& runElement, size_t from, size_t to) const
148 {
149 RequireNotNull (imager);
150 StyleRunElement re = MungeRunElement (runElement);
151 if (re.fMarker == nullptr) {
152 return (imager->MeasureSegmentHeight_ (this->MakeFontSpec (imager, re), from, to));
153 }
154 else {
155 return (re.fMarker->MeasureSegmentHeight (imager, re, from, to));
156 }
157 }
158 template <class BASECLASS>
159 DistanceType SimpleStyleMarkerWithExtraDraw<BASECLASS>::MeasureSegmentBaseLine (const StyledTextImager* imager,
160 const StyleRunElement& runElement, size_t from, size_t to) const
161 {
162 RequireNotNull (imager);
163 StyleRunElement re = MungeRunElement (runElement);
164 if (re.fMarker == nullptr) {
165 return (imager->MeasureSegmentBaseLine_ (this->MakeFontSpec (imager, re), from, to));
166 }
167 else {
168 return (re.fMarker->MeasureSegmentBaseLine (imager, re, from, to));
169 }
170 }
171#endif
172
173 /*
174 ********************************************************************************
175 ************* SimpleStyleMarkerWithLightUnderline<BASECLASS> *******************
176 ********************************************************************************
177 */
178#if qStroika_Frameworks_Led_SupportGDI
179 template <typename BASECLASS>
180 void SimpleStyleMarkerWithLightUnderline<BASECLASS>::DrawExtra (const StyledTextImager* /*imager*/, const StyleRunElement& /*runElement*/,
181 Tablet* tablet, size_t /*from*/, size_t /*to*/, const TextLayoutBlock& /*text*/,
182 const Led_Rect& drawInto, CoordinateType useBaseLine, DistanceType pixelsDrawn)
183 {
184 Color lightColor = Color::kWhite / 2 + GetUnderlineBaseColor () / 2; // (white - baseColor)/2 + baseColor, but careful to avoid int overflow...
185#if qStroika_Foundation_Common_Platform_Windows
186 Pen pen (PS_DOT, 1, lightColor.GetOSRep ());
187#elif qStroika_Foundation_Common_Platform_MacOS
188 Pen pen (patCopy, &Pen::kGrayPattern, lightColor);
189#elif qStroika_FeatureSupported_XWindows
190 Pen pen;
191#endif
192 GDI_Obj_Selector penWrapper (tablet, pen);
193 CoordinateType underlineAt = useBaseLine;
194 if (underlineAt + 1 < drawInto.bottom) {
195 underlineAt += 1;
196 }
197 tablet->MoveTo (Led_Point (underlineAt, drawInto.left));
198 tablet->LineTo (Led_Point (underlineAt, drawInto.left + pixelsDrawn));
199 }
200#endif
201 template <typename BASECLASS>
202 inline Color SimpleStyleMarkerWithLightUnderline<BASECLASS>::GetUnderlineBaseColor () const
203 {
204 return Color::kBlack;
205 }
206
207#if qStroika_Frameworks_Led_SupportGDI
208 /*
209 ********************************************************************************
210 *************************** StyledTextImager ***********************************
211 ********************************************************************************
212 */
213 inline void StyledTextImager::Invariant () const
214 {
215#if qStroika_Foundation_Debug_AssertionsChecked and qStroika_Frameworks_Led_HeavyDebugging
216 Invariant_ ();
217#endif
218 }
219#endif
220
221}
#define AssertNotNull(p)
Definition Assertions.h:333
#define RequireNotNull(p)
Definition Assertions.h:347