Giter Site home page Giter Site logo

Comments (2)

handerss-spotfire avatar handerss-spotfire commented on July 28, 2024

Maybe it enough to always line break at a line break character if that occurs before the max width of the text block?

E.g:

diff --git a/Topten.RichTextKit/TextBlock.cs b/Topten.RichTextKit/TextBlock.cs
index 1b29bda..9403b80 100644
--- a/Topten.RichTextKit/TextBlock.cs
+++ b/Topten.RichTextKit/TextBlock.cs
@@ -1475,10 +1475,15 @@ namespace Topten.RichTextKit
                     fr = _fontRuns[frIndex];
                     var room = _maxWidthResolved - fr.XCoord;
                     frSplitIndex = frIndex;
-                    codePointIndexSplit = fr.FindBreakPosition(room, frSplitIndex == frIndexStartOfLine);
-                    codePointIndexWrap = codePointIndexSplit;
-                    while (codePointIndexWrap < _codePoints.Length && UnicodeClasses.LineBreakClass(_codePoints[codePointIndexWrap]) == LineBreakClass.SP)
-                        codePointIndexWrap++;
+                    var breakPosition = fr.FindBreakPosition(room, frSplitIndex == frIndexStartOfLine);
+
+                    if (breakPosition < codePointIndexSplit)
+                    {
+                        codePointIndexSplit = breakPosition;
+                        codePointIndexWrap = codePointIndexSplit;
+                        while (codePointIndexWrap < _codePoints.Length && UnicodeClasses.LineBreakClass(_codePoints[codePointIndexWrap]) == LineBreakClass.SP)
+                            codePointIndexWrap++;
+                    }
                 }
 
                 // Split it

from richtextkit.

handerss-spotfire avatar handerss-spotfire commented on July 28, 2024

The patch above is a bit too naive since codePointIndexSplit can be negative if no non-character breaks were found. I have modified it for our use-case such that it differentiates between required text breaks and others, and that it prefers to break at characters if that happens later than a break position (leads to behavior similar to StringTrimming.EllipsisCharacter in GDI+).

I'll submit a PR if testing is successful.

from richtextkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.