Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
StandardStyledTextImager.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Frameworks_Led_StandardStyledTextImager_h_
5#define _Stroika_Frameworks_Led_StandardStyledTextImager_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
9/*
10@MODULE: StandardStyledTextImager
11@DESCRIPTION: <p>@'StandardStyledTextImager' is not intended to be a general and flexible
12 style run interface. Rather, it is intended to mimic the usual style-run
13 support found in other text editors, like MS-Word, or Apples TextEdit.</p>
14 <p>It keeps style runs in markers which are a subclass of StyledTextImager::StyleMarker,
15 called @'StandardStyledTextImager::StandardStyleMarker'.</p>
16
17 */
18
19#include "Stroika/Frameworks/Led/StyledTextImager.h"
20
21namespace Stroika::Frameworks::Led {
22
23 /*
24 @CLASS: StyledInfoSummaryRecord
25 @BASES: @'FontSpecification'
26 @DESCRIPTION: <p>Add a length attribute to @'FontSpecification'. Used in specifying style runs by
27 @'StandardStyledTextImager'.</p>
28 */
29 struct StyledInfoSummaryRecord : public FontSpecification {
30 public:
31 StyledInfoSummaryRecord (const FontSpecification& fontSpec, size_t length);
32
33 public:
34 size_t fLength;
35 };
36
37 /*
38 @CLASS: StandardStyledTextImager::AbstractStyleDatabaseRep
39 @BASES: @'MarkerOwner'
40 @DESCRIPTION: <p>xxx.</p>
41 */
42 class AbstractStyleDatabaseRep : public virtual MarkerOwner {
43 private:
44 using inherited = MarkerOwner;
45
46 public:
47 virtual vector<StyledInfoSummaryRecord> GetStyleInfo (size_t charAfterPos, size_t nTCharsFollowing) const = 0;
48 virtual void SetStyleInfo (size_t charAfterPos, size_t nTCharsFollowing, const IncrementalFontSpecification& styleInfo) = 0;
49 nonvirtual void SetStyleInfo (size_t charAfterPos, size_t nTCharsFollowing, const vector<StyledInfoSummaryRecord>& styleInfos);
50 virtual void SetStyleInfo (size_t charAfterPos, size_t nTCharsFollowing, size_t nStyleInfos, const StyledInfoSummaryRecord* styleInfos) = 0;
51
52 // Debug support
53 public:
54 nonvirtual void Invariant () const;
55#if qStroika_Foundation_Debug_AssertionsChecked
56 protected:
57 virtual void Invariant_ () const;
58#endif
59 };
60
61 /*
62 @CLASS: StandardStyledTextImager::StandardStyleMarker
63 @BASES: @'StyledTextImager::StyleMarker'
64 @DESCRIPTION:
65 <p>Private, implementation detail class. Part of @'StandardStyledTextImager' implementation.</p>
66 <p>Should NOT be subclassed. These participate in routines to grab
67 runs of style info, etc, and aren't really designed to be subclassed. Also, all elements
68 of this type in the text buffer are summarily deleted upon deletion of the owning StyleDatabase.</p>
69 */
70 class StandardStyleMarker : public StyleMarker {
71 private:
72 using inherited = StyleMarker;
73
74 public:
75 StandardStyleMarker (const FontSpecification& styleInfo = GetStaticDefaultFont ());
76
77#if qStroika_Frameworks_Led_SupportGDI
78 public:
79 virtual void DrawSegment (const StyledTextImager* imager, const StyleRunElement& runElement, Tablet* tablet, size_t from, size_t to,
80 const TextLayoutBlock& text, const Led_Rect& drawInto, const Led_Rect& /*invalidRect*/,
81 CoordinateType useBaseLine, DistanceType* pixelsDrawn) override;
82 virtual void MeasureSegmentWidth (const StyledTextImager* imager, const StyleRunElement& runElement, size_t from, size_t to,
83 const Led_tChar* text, DistanceType* distanceResults) const override;
84 virtual DistanceType MeasureSegmentHeight (const StyledTextImager* imager, const StyleRunElement& runElement, size_t from, size_t to) const override;
85 virtual DistanceType MeasureSegmentBaseLine (const StyledTextImager* imager, const StyleRunElement& runElement, size_t from, size_t to) const override;
86#endif
87
88 public:
89 nonvirtual FontSpecification GetInfo () const;
90 nonvirtual void SetInfo (const FontSpecification& fsp);
91
92 public:
93 FontSpecification fFontSpecification;
94 };
95
96 DISABLE_COMPILER_MSC_WARNING_START (4250) // inherits via dominance warning
97 /*
98 @CLASS: StandardStyledTextImager::StyleDatabaseRep
99 @BASES: @'MarkerCover'<@'StandardStyleMarker',@'FontSpecification',@'IncrementalFontSpecification'>
100 @DESCRIPTION: <p>Reference counted object which stores all the style runs objects for a
101 @'StandardStyledTextImager'. An explicit storage object like this is used, instead of using
102 the @'StandardStyledTextImager' itself, so as too allow you to have either multiple views onto the
103 same text which use the SAME database of style runs, or to allow using different style info databases,
104 all live on the same text.</p>
105 */
106 class StyleDatabaseRep : public AbstractStyleDatabaseRep, private MarkerCover<StandardStyleMarker, FontSpecification, IncrementalFontSpecification> {
107 private:
108 using inheritedMC = MarkerCover<StandardStyleMarker, FontSpecification, IncrementalFontSpecification>;
109
110 public:
111 StyleDatabaseRep (TextStore& textStore);
112
113 public:
114 virtual vector<StyledInfoSummaryRecord> GetStyleInfo (size_t charAfterPos, size_t nTCharsFollowing) const override;
115 virtual void SetStyleInfo (size_t charAfterPos, size_t nTCharsFollowing, const IncrementalFontSpecification& styleInfo) override;
116 virtual void SetStyleInfo (size_t charAfterPos, size_t nTCharsFollowing, size_t nStyleInfos, const StyledInfoSummaryRecord* styleInfos) override;
117
118#if qStroika_Foundation_Debug_AssertionsChecked
119 protected:
120 virtual void Invariant_ () const override;
121#endif
122 };
123 DISABLE_COMPILER_MSC_WARNING_END (4250) // inherits via dominance warning
124
125 /*
126 @CLASS: SimpleStyleMarkerByIncrementalFontSpecStandardStyleMarkerHelper
127 @BASES: BASECLASS
128 @DESCRIPTION: <p>Simple helper class so that @'SimpleStyleMarkerByIncrementalFontSpec<BASECLASS>' will use the font specification of any
129 embedded @'StandardStyledTextImager::StandardStyleMarker' will have its associated @'FontSpecification' copied out and used
130 in the FontSpec.</p>
131 <p>As a kludge - this class depends on the user ALSO using the template @'SimpleStyleMarkerWithExtraDraw<BASECLASS>'. We override
132 its @'SimpleStyleMarkerWithExtraDraw<BASECLASS>::MungeRunElement' () method. This isn't strictly necesary, but it saves us alot of code.
133 That way - we can just change the RunElt to return nullptr for the marker - and then the caller will use its default algorithm, and call
134 the MakeFontSpec () method.</p>
135 <p>The nature of class class could change in the future - so its not recomended that anyone directly use it.</p>
136 */
137 template <class BASECLASS>
138 class SimpleStyleMarkerByIncrementalFontSpecStandardStyleMarkerHelper : public BASECLASS {
139 private:
140 using inherited = BASECLASS;
141
142 protected:
143 virtual StyleRunElement MungeRunElement (const StyleRunElement& inRunElt) const override;
144
145#if qStroika_Frameworks_Led_SupportGDI
146 protected:
147 virtual FontSpecification MakeFontSpec (const StyledTextImager* imager, const StyleRunElement& runElement) const override;
148#endif
149
150 private:
151 mutable FontSpecification fFSP;
152 };
153
154#if qStroika_Frameworks_Led_SupportGDI
155 /*
156 @CLASS: StandardStyledTextImager
157 @BASES: virtual @'StyledTextImager'
158 @DESCRIPTION: <p>StandardStyledTextImager is not intended to be a general and flexible
159 style run interface (like @'StyledTextImager'). Rather, it is intended to mimic
160 traditional API for handling styled text found in other text editors, like MS-Word,
161 or Apples TextEdit.
162 </p>
163
164 <p>You can specify ranges of text, and apply font styles to them.
165 And there are routines (like @'StandardStyledTextImager::GetContinuousStyleInfo' etc)
166 to help find/idenitfiy font style runs, etc.</p>
167
168 <p>This class is built trivially ontop of the @'StyledTextImager'.
169 The rendering of styles and layout issues are all taken care of.
170 This class is merely responsable for preserving a disjoint cover (partition) of styles
171 (@'StandardStyledTextImager::StandardStyleMarker'), and coalescing adjacent
172 ones that have the same font info.</p>
173 */
174 class StandardStyledTextImager : public virtual StyledTextImager {
175 private:
176 using inherited = StyledTextImager;
177
178 protected:
179 StandardStyledTextImager () = default;
180 virtual ~StandardStyledTextImager () = default;
181
182 protected:
183 virtual void HookLosingTextStore () override;
184 nonvirtual void HookLosingTextStore_ ();
185 virtual void HookGainedNewTextStore () override;
186 nonvirtual void HookGainedNewTextStore_ ();
187
188 /*
189 * Interface to getting and setting STANDARD style info. These routines ignore
190 * custom style markers.
191 */
192 public:
193 nonvirtual FontSpecification GetStyleInfo (size_t charAfterPos) const;
194 nonvirtual vector<StyledInfoSummaryRecord> GetStyleInfo (size_t charAfterPos, size_t nTCharsFollowing) const;
195 nonvirtual void SetStyleInfo (size_t charAfterPos, size_t nTCharsFollowing, const IncrementalFontSpecification& styleInfo);
196 nonvirtual void SetStyleInfo (size_t charAfterPos, size_t nTCharsFollowing, const vector<StyledInfoSummaryRecord>& styleInfos);
197 nonvirtual void SetStyleInfo (size_t charAfterPos, size_t nTCharsFollowing, size_t nStyleInfos, const StyledInfoSummaryRecord* styleInfos);
198
199 public:
200 virtual FontMetrics GetFontMetricsAt (size_t charAfterPos) const override;
201
202 public:
203 virtual FontSpecification GetDefaultSelectionFont () const override;
204
205 // Do macstyle lookalike routines (DoSetStyle, DoContinuous etc)
206 public:
207 virtual IncrementalFontSpecification GetContinuousStyleInfo (size_t from, size_t nTChars) const; // was DoContinuousStyle()
208 protected:
209 nonvirtual IncrementalFontSpecification GetContinuousStyleInfo_ (const vector<StyledInfoSummaryRecord>& summaryInfo) const;
210
211#if qStroika_Foundation_Common_Platform_MacOS
212 public:
213 nonvirtual bool DoContinuousStyle_Mac (size_t from, size_t nTChars, short* mode, TextStyle* theStyle);
214#endif
215
216#if qStroika_Foundation_Common_Platform_MacOS
217 // macstyle routines to get/set 'styl' resources for range of text...
218 public:
219 static vector<StyledInfoSummaryRecord> Convert (const ScrpSTElement* teScrapFmt, size_t nElts);
220 static void Convert (const vector<StyledInfoSummaryRecord>& fromLedStyleRuns, ScrpSTElement* teScrapFmt); // Assumed pre-alloced and same legnth as fromLedStyleRuns
221#endif
222
223 public:
224 nonvirtual shared_ptr<AbstractStyleDatabaseRep> GetStyleDatabase () const;
225 nonvirtual void SetStyleDatabase (const shared_ptr<AbstractStyleDatabaseRep>& styleDatabase);
226
227 protected:
228 virtual void HookStyleDatabaseChanged ();
229
230 private:
231 shared_ptr<AbstractStyleDatabaseRep> fStyleDatabase{nullptr};
232 bool fICreatedDatabase{false};
233
234// Debug support
235#if qStroika_Foundation_Debug_AssertionsChecked
236 protected:
237 virtual void Invariant_ () const;
238#endif
239 };
240
241#endif
242
243}
244
245/*
246 ********************************************************************************
247 ***************************** Implementation Details ***************************
248 ********************************************************************************
249 */
250#include "StandardStyledTextImager.inl"
251
252#endif /*_Stroika_Frameworks_Led_StandardStyledTextImager_h_*/
Profile Convert(const VariantValue &v)
Definition Profile.cpp:50