[Libreoffice-commits] core.git: cppcanvas/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Oct 22 22:56:15 UTC 2018


 cppcanvas/source/mtfrenderer/mtftools.cxx |  197 ++++++++++++++----------------
 1 file changed, 93 insertions(+), 104 deletions(-)

New commits:
commit ae9f37ba753519ae4a2ae6384d052d417359602f
Author:     Mark Hung <marklh9 at gmail.com>
AuthorDate: Sun Oct 21 00:04:33 2018 +0800
Commit:     Mark Hung <marklh9 at gmail.com>
CommitDate: Tue Oct 23 00:55:50 2018 +0200

    tdf#100236 Implement linestyles with dash and dots.
    
    Allow append dashes to have dash and dot line styles.
    Segment length parameters were taken from cppcanvas, also restructure
    the code to use the same appendDashes function.
    
    Change-Id: I17c0796dbe722c4c6d5e91d0e318570a52a2514c
    Reviewed-on: https://gerrit.libreoffice.org/62084
    Tested-by: Jenkins
    Reviewed-by: Mark Hung <marklh9 at gmail.com>

diff --git a/cppcanvas/source/mtfrenderer/mtftools.cxx b/cppcanvas/source/mtfrenderer/mtftools.cxx
index 75c7d6069146..0680e05f3ca8 100644
--- a/cppcanvas/source/mtfrenderer/mtftools.cxx
+++ b/cppcanvas/source/mtfrenderer/mtftools.cxx
@@ -319,28 +319,92 @@ namespace cppcanvas
                         ::basegfx::B2DRectangle( nX1, nY1, nX2, nY2 ) ) );
             }
 
-            void appendDashes( ::basegfx::B2DPolyPolygon&   o_rPoly,
+            bool appendDashes( ::basegfx::B2DPolyPolygon&   o_rPoly,
                                const double                 nX,
-                               const double                 nY,
+                               double                       nY,
                                const double                 nLineWidth,
-                               const double                 nLineHeight,
-                               const double                 nDashWidth,
-                               const double                 nDashSkip )
+                               double                       nLineHeight,
+                               sal_Int8                     nLineStyle,
+                               bool                         bIsOverline)
             {
-                const sal_Int32 nNumLoops(
-                    static_cast< sal_Int32 >(
-                        std::max( 1.0,
-                                    nLineWidth / nDashSkip ) + .5) );
+                static const int aDottedArray[]     = { 1, 1, 0};               // DOTTED LINE
+                static const int aDotDashArray[]    = { 1, 1, 4, 1, 0};         // DASHDOT
+                static const int aDashDotDotArray[] = { 1, 1, 1, 1, 4, 1, 0};   // DASHDOTDOT
+                static const int aDashedArray[]     = { 5, 2, 0};               // DASHED LINE
+                static const int aLongDashArray[]   = { 7, 2, 0};               // LONGDASH
+                const int *pArray = nullptr;
+                bool bIsBold = false;
+
+                switch(nLineStyle)
+                {
+                    case LINESTYLE_BOLDDOTTED:
+                        bIsBold = true;
+                        BOOST_FALLTHROUGH;
+                    case LINESTYLE_DOTTED:
+                        pArray = aDottedArray;
+                    break;
+
+                    case LINESTYLE_BOLDDASH:
+                        bIsBold = true;
+                        BOOST_FALLTHROUGH;
+                    case LINESTYLE_DASH:
+                        pArray = aDashedArray;
+                    break;
+
+                    case LINESTYLE_BOLDLONGDASH:
+                        bIsBold = true;
+                        BOOST_FALLTHROUGH;
+                    case LINESTYLE_LONGDASH:
+                        pArray = aLongDashArray;
+                    break;
+
+                    case LINESTYLE_BOLDDASHDOT:
+                        bIsBold = true;
+                        BOOST_FALLTHROUGH;
+                    case LINESTYLE_DASHDOT:
+                        pArray = aDotDashArray;
+                    break;
+                    case LINESTYLE_BOLDDASHDOTDOT:
+                        bIsBold = true;
+                        BOOST_FALLTHROUGH;
+                    case LINESTYLE_DASHDOTDOT:
+                        pArray = aDashDotDotArray;
+                    break;
+                }
 
-                double x = nX;
-                for( sal_Int32 i=0; i<nNumLoops; ++i )
+                if (!pArray)
+                    return false;
+
+                if (bIsBold)
                 {
-                    appendRect( o_rPoly,
-                                x,              nY,
-                                x + nDashWidth, nY + nLineHeight );
+                    if (bIsOverline)
+                        nY -= nLineHeight;
+
+                    nLineHeight *= 2;
+                }
+
+                const double nEnd = nX + nLineWidth;
+                sal_Int32 nIndex = 0;
+                bool bAppend = true;
+                double nX1 = nX;
+
+                while(nX1 < nEnd)
+                {
+                    if (pArray[nIndex] == 0)
+                        nIndex = 0;
+
+                    const double nX2 = std::min(nEnd, nX1 + pArray[nIndex] * nLineHeight);
+
+                    if (bAppend)
+                        appendRect(o_rPoly, nX1, nY, nX2, nY + nLineHeight);
+
+                    nX1 = nX2;
 
-                    x += nDashSkip;
+                    ++nIndex;
+
+                    bAppend = !bAppend;
                 }
+                return true;
             }
         }
 
@@ -385,17 +449,6 @@ namespace cppcanvas
                         rLineWidth,
                         rTextLineInfo.mnOverlineOffset + rTextLineInfo.mnOverlineHeight );
                     break;
-
-                case LINESTYLE_BOLDDOTTED:    // TODO(F3): NYI
-                    // FALLTHROUGH intended
-                case LINESTYLE_BOLDDASH:      // TODO(F3): NYI
-                    // FALLTHROUGH intended
-                case LINESTYLE_BOLDLONGDASH:  // TODO(F3): NYI
-                    // FALLTHROUGH intended
-                case LINESTYLE_BOLDDASHDOT:   // TODO(F3): NYI
-                    // FALLTHROUGH intended
-                case LINESTYLE_BOLDDASHDOTDOT:// TODO(F3): NYI
-                    // FALLTHROUGH intended
                 case LINESTYLE_BOLD:
                     appendRect(
                         aTextLinesPolyPoly,
@@ -424,46 +477,19 @@ namespace cppcanvas
                         rTextLineInfo.mnOverlineOffset + rTextLineInfo.mnOverlineHeight * 2.0 );
                     break;
 
-                case LINESTYLE_DASHDOTDOT:    // TODO(F3): NYI
-                    // FALLTHROUGH intended
-                case LINESTYLE_DOTTED:
-                    appendDashes(
-                        aTextLinesPolyPoly,
-                        rStartPos.getX(),
-                        rStartPos.getY() + rTextLineInfo.mnOverlineOffset,
-                        rLineWidth,
-                        rTextLineInfo.mnOverlineHeight,
-                        rTextLineInfo.mnOverlineHeight,
-                        2*rTextLineInfo.mnOverlineHeight );
-                    break;
-
-                case LINESTYLE_DASHDOT:       // TODO(F3): NYI
-                    // FALLTHROUGH intended
-                case LINESTYLE_DASH:
-                    appendDashes(
-                        aTextLinesPolyPoly,
-                        rStartPos.getX(),
-                        rStartPos.getY() + rTextLineInfo.mnOverlineOffset,
-                        rLineWidth,
-                        rTextLineInfo.mnOverlineHeight,
-                        3*rTextLineInfo.mnOverlineHeight,
-                        6*rTextLineInfo.mnOverlineHeight );
-                    break;
-
-                case LINESTYLE_LONGDASH:
-                    appendDashes(
+                default:
+                    if (!appendDashes(
                         aTextLinesPolyPoly,
                         rStartPos.getX(),
                         rStartPos.getY() + rTextLineInfo.mnOverlineOffset,
                         rLineWidth,
                         rTextLineInfo.mnOverlineHeight,
-                        6*rTextLineInfo.mnOverlineHeight,
-                        12*rTextLineInfo.mnOverlineHeight );
-                    break;
-
-                default:
-                    ENSURE_OR_THROW( false,
+                        rTextLineInfo.mnOverlineStyle,
+                        true))
+                    {
+                        ENSURE_OR_THROW( false,
                                       "::cppcanvas::internal::createTextLinesPolyPolygon(): Unexpected overline case" );
+                    }
             }
 
             switch( rTextLineInfo.mnUnderlineStyle )
@@ -498,16 +524,6 @@ namespace cppcanvas
                         rTextLineInfo.mnUnderlineOffset + rTextLineInfo.mnLineHeight );
                     break;
 
-                case LINESTYLE_BOLDDOTTED:    // TODO(F3): NYI
-                    // FALLTHROUGH intended
-                case LINESTYLE_BOLDDASH:      // TODO(F3): NYI
-                    // FALLTHROUGH intended
-                case LINESTYLE_BOLDLONGDASH:  // TODO(F3): NYI
-                    // FALLTHROUGH intended
-                case LINESTYLE_BOLDDASHDOT:   // TODO(F3): NYI
-                    // FALLTHROUGH intended
-                case LINESTYLE_BOLDDASHDOTDOT:// TODO(F3): NYI
-                    // FALLTHROUGH intended
                 case LINESTYLE_BOLD:
                     appendRect(
                         aTextLinesPolyPoly,
@@ -536,46 +552,19 @@ namespace cppcanvas
                         rTextLineInfo.mnUnderlineOffset + 3*rTextLineInfo.mnLineHeight );
                     break;
 
-                case LINESTYLE_DASHDOTDOT:    // TODO(F3): NYI
-                    // FALLTHROUGH intended
-                case LINESTYLE_DOTTED:
-                    appendDashes(
-                        aTextLinesPolyPoly,
-                        rStartPos.getX(),
-                        rStartPos.getY() + rTextLineInfo.mnUnderlineOffset,
-                        rLineWidth,
-                        rTextLineInfo.mnLineHeight,
-                        rTextLineInfo.mnLineHeight,
-                        2*rTextLineInfo.mnLineHeight );
-                    break;
-
-                case LINESTYLE_DASHDOT:       // TODO(F3): NYI
-                    // FALLTHROUGH intended
-                case LINESTYLE_DASH:
-                    appendDashes(
-                        aTextLinesPolyPoly,
-                        rStartPos.getX(),
-                        rStartPos.getY() + rTextLineInfo.mnUnderlineOffset,
-                        rLineWidth,
-                        rTextLineInfo.mnLineHeight,
-                        3*rTextLineInfo.mnLineHeight,
-                        6*rTextLineInfo.mnLineHeight );
-                    break;
-
-                case LINESTYLE_LONGDASH:
-                    appendDashes(
+                default:
+                    if (!appendDashes(
                         aTextLinesPolyPoly,
                         rStartPos.getX(),
                         rStartPos.getY() + rTextLineInfo.mnUnderlineOffset,
                         rLineWidth,
                         rTextLineInfo.mnLineHeight,
-                        6*rTextLineInfo.mnLineHeight,
-                        12*rTextLineInfo.mnLineHeight );
-                    break;
-
-                default:
-                    ENSURE_OR_THROW( false,
+                        rTextLineInfo.mnUnderlineStyle,
+                        false))
+                    {
+                        ENSURE_OR_THROW( false,
                                       "::cppcanvas::internal::createTextLinesPolyPolygon(): Unexpected underline case" );
+                    }
             }
 
             switch( rTextLineInfo.mnStrikeoutStyle )


More information about the Libreoffice-commits mailing list