Sfoglia il codice sorgente

fix problem rendering formatted text with AutoLineBreak Style

Kolja Strohm 1 mese fa
parent
commit
49ff1d3696
2 ha cambiato i file con 15 aggiunte e 11 eliminazioni
  1. 12 9
      TextFeld.cpp
  2. 3 2
      TextFeld.h

+ 12 - 9
TextFeld.cpp

@@ -673,7 +673,8 @@ void TextFeld::addLineBreaks(const char* spacing)
     setFormattedText(addLineBreaksToText(tm->text->getText(), spacing));
 }
 
-Text TextFeld::addLineBreaksToText(const char* txt, const char* spacing) const
+Text TextFeld::addLineBreaksToText(
+    const char* txt, const char* spacing, bool includeFormat) const
 {
     int lastPos = -1;
     int lastPos2 = -1;
@@ -695,48 +696,49 @@ Text TextFeld::addLineBreaksToText(const char* txt, const char* spacing) const
     last.rendererIndex = 0;
     for (int i = 0; i < len; ++i)
     {
-        if (last.fontSize != tm->current.fontSize)
+        if (last.fontSize != tm->current.fontSize && includeFormat)
         {
             Text param("\x2");
             param.appendHex((char)tm->current.fontSize);
             result += param;
             last.fontSize = tm->current.fontSize;
         }
-        if (last.fontColor != tm->current.fontColor)
+        if (last.fontColor != tm->current.fontColor && includeFormat)
         {
             Text param("\x3");
             param.appendHex(tm->current.fontColor);
             result += param;
             last.fontColor = tm->current.fontColor;
         }
-        if (last.selectedColor != tm->current.selectedColor)
+        if (last.selectedColor != tm->current.selectedColor && includeFormat)
         {
             Text param("\x4");
             param.appendHex(tm->current.selectedColor);
             result += param;
             last.selectedColor = tm->current.selectedColor;
         }
-        if (last.selectedBackcroundColor != tm->current.selectedBackcroundColor)
+        if (last.selectedBackcroundColor != tm->current.selectedBackcroundColor
+            && includeFormat)
         {
             Text param("\x5");
             param.appendHex(tm->current.selectedBackcroundColor);
             result += param;
             last.selectedBackcroundColor = tm->current.selectedBackcroundColor;
         }
-        if (last.underlined != tm->current.underlined)
+        if (last.underlined != tm->current.underlined && includeFormat)
         {
             char tmp[2] = {tm->current.underlined ? (char)1 : (char)7, 0};
             result += tmp;
             last.underlined = tm->current.underlined;
         }
-        if (last.interactParam != tm->current.interactParam)
+        if (last.interactParam != tm->current.interactParam && includeFormat)
         {
             Text param("\x8");
             param.appendHex(tm->current.interactParam);
             result += param;
             last.interactParam = tm->current.interactParam;
         }
-        if (last.rendererIndex != tm->current.rendererIndex)
+        if (last.rendererIndex != tm->current.rendererIndex && includeFormat)
         {
             Text param("\x6");
             param.appendHex((char)tm->current.rendererIndex);
@@ -1510,7 +1512,8 @@ void TextFeld::render(Bild& zRObj) // zeichenet nach zRObj
     if (hatStyle(Style::AutoLineBreak))
     {
         txtWithLineBreaks = addLineBreaksToText(tm->text->getText(),
-            autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "");
+            autoLineBreakSpacing ? autoLineBreakSpacing->getText() : "",
+            0);
         text = txtWithLineBreaks;
         len = txtWithLineBreaks.getLength();
     }

+ 3 - 2
TextFeld.h

@@ -185,8 +185,9 @@ namespace Framework
         //! Zeilenumbrüche eingefügt werden sollen \param spacing ein text, der
         //! direkt nach jedem eingefügten Zeilenumbruch eingefügt wird \return
         //! der Text mit zeilenumbrüchen
-        DLLEXPORT Text addLineBreaksToText(
-            const char* txt, const char* spacing = "") const;
+        DLLEXPORT Text addLineBreaksToText(const char* txt,
+            const char* spacing = "",
+            bool includeFormat = 1) const;
         //! setzt eine Zeichenfolge die mit dem style AutoLineBreak nach jedem
         //! eingefügten Zeilenumbruch eingefügt wird
         DLLEXPORT void setAutoLineBreakSpacing(const char* spacing);