@@ -180,7 +180,14 @@ enum class HorizontalAlignment {
180
180
Left, Center, Right
181
181
};
182
182
enum class FontStyle {
183
- Default, Monospaced, Serif, SansSerif, Casual, Cursive, SmallCaps
183
+ Default,
184
+ Monospaced, // Courier New
185
+ Proportional, // Times New Roman
186
+ MonospacedSans, // Lucida Console
187
+ ProportionalSans, // Roboto
188
+ Casual, // Comic Sans!
189
+ Cursive, // Monotype Corsiva
190
+ SmallCapitals // (Arial with font-variant: small-caps)
184
191
};
185
192
enum class EdgeType {
186
193
None, HardShadow, Bevel, GlowOutline, SoftShadow
@@ -212,6 +219,11 @@ E enumFromString(const std::string &s) {
212
219
}
213
220
}
214
221
222
+ template <typename E>
223
+ std::string enumToIntString (E e) {
224
+ return std::to_string (magic_enum::enum_integer (e));
225
+
226
+ }
215
227
216
228
template <typename E>
217
229
std::string enumOptionsComment () {
@@ -236,7 +248,7 @@ struct ChatParams {
236
248
Color textEdgeColor = {254 , 254 , 254 , 254 };
237
249
238
250
EdgeType textEdgeType = EdgeType::SoftShadow;
239
- FontStyle fontStyle = FontStyle::SansSerif ;
251
+ FontStyle fontStyle = FontStyle::MonospacedSans ;
240
252
int fontSizePercent = 0 ;
241
253
242
254
TextAlignment textAlignment = TextAlignment::Left;
@@ -466,7 +478,10 @@ std::pair<std::string, std::vector<std::string>> wrapMessage(std::string usernam
466
478
continue ;
467
479
}
468
480
if (utf8_length (word) < availableSpace) {
469
- if (!firstWord) lines.back () += " " ;
481
+ if (!firstWord) {
482
+ lines.back () += " " ;
483
+ availableSpace--;
484
+ }
470
485
lines.back () += word;
471
486
availableSpace -= utf8_length (word);
472
487
} else {
@@ -476,6 +491,9 @@ std::pair<std::string, std::vector<std::string>> wrapMessage(std::string usernam
476
491
}
477
492
firstWord = false ;
478
493
}
494
+ // for (const auto& line :lines){
495
+ // assert(utf8_length(line)<=maxWidth);
496
+ // }
479
497
return {username, lines};
480
498
}
481
499
@@ -536,13 +554,13 @@ std::string generateXML(const std::vector<ChatMessage> &messages, const ChatPara
536
554
pen->SetAttribute (" bo" , std::to_string (params.textBackgroundColor .a ).c_str ());
537
555
538
556
// Set edge attributes if provided.
539
- std::string textEdgeType = enumToString (params.textEdgeType );
557
+ std::string textEdgeType = enumToIntString (params.textEdgeType );
540
558
if (!textEdgeType.empty ()) {
541
559
pen->SetAttribute (" ec" , static_cast <std::string>(params.textEdgeColor ).c_str ());
542
560
pen->SetAttribute (" et" , textEdgeType.c_str ());
543
561
}
544
562
545
- pen->SetAttribute (" fs" , enumToString (params.fontStyle ).c_str ());
563
+ pen->SetAttribute (" fs" , enumToIntString (params.fontStyle ).c_str ());
546
564
pen->SetAttribute (" sz" , std::to_string (params.fontSizePercent ).c_str ());
547
565
head->InsertEndChild (pen);
548
566
kv.second = std::to_string (penIndex);
@@ -552,7 +570,7 @@ std::string generateXML(const std::vector<ChatMessage> &messages, const ChatPara
552
570
// Create workspace element for positioning.
553
571
XMLElement *ws = doc.NewElement (" ws" );
554
572
ws->SetAttribute (" id" , " 1" ); // default workspace id
555
- ws->SetAttribute (" ju" , enumToString (params.textAlignment ).c_str ());
573
+ ws->SetAttribute (" ju" , enumToIntString (params.textAlignment ).c_str ());
556
574
head->InsertEndChild (ws);
557
575
558
576
// Create write positioning (wp) elements.
@@ -616,27 +634,6 @@ Color getRandomColor(const std::string &username) {
616
634
617
635
}
618
636
619
- int test () {
620
- // Example inputs.
621
- std::string username = " Alice1234" ;
622
- std::string separator = " : " ;
623
- std::string message = " Hello this is a long message that we will try to wrap correctly even if there are verylongwordswithoutanyspaces" ;
624
- int maxWidth = 30 ;
625
-
626
- auto [displayName, wrappedLines] = wrapMessage (username, separator, message, maxWidth);
627
-
628
- // Print the results.
629
- std::cout << " Username: " << displayName << " \n " ;
630
- std::cout << " Message:\n " ;
631
- // Print the full first line as it would appear when concatenated.
632
- std::string fullFirstLine = displayName + wrappedLines[0 ];
633
- std::cout << fullFirstLine << " |" << utf8_length (fullFirstLine) << " \n " ;
634
- for (size_t i = 1 ; i < wrappedLines.size (); ++i) {
635
- std::cout << wrappedLines[i] << " |" << utf8_length (wrappedLines[i]) << " \n " ;
636
- }
637
-
638
- return 0 ;
639
- }
640
637
641
638
642
639
0 commit comments