Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


Hi,

here is the patch to reduce code which seems to be copy&pasted (cf. Duplicate code: GlyphSet::DrawGlyphs() and GlyphSet::ImplDrawText() / 27.2.2012)

Christina
From 0c393ff76ec608817c51e228fa7e6c019d844c97 Mon Sep 17 00:00:00 2001
From: Christina Rossmanith <ChrRossmanith@web.de>
Date: Tue, 28 Feb 2012 11:04:12 +0100
Subject: [PATCH] Reduced duplicate code (simian) / vcl/generic/print/glyphset.cxx

---
 vcl/generic/print/glyphset.cxx |   76 +++++++---------------------------------
 vcl/generic/print/glyphset.hxx |    3 +-
 2 files changed, 15 insertions(+), 64 deletions(-)

diff --git a/vcl/generic/print/glyphset.cxx b/vcl/generic/print/glyphset.cxx
index 5b03666..6d4cfde 100644
--- a/vcl/generic/print/glyphset.cxx
+++ b/vcl/generic/print/glyphset.cxx
@@ -479,7 +479,8 @@ void GlyphSet::DrawGlyphs(
                           const sal_uInt32* pGlyphIds,
                           const sal_Unicode* pUnicodes,
                           sal_Int16 nLen,
-                          const sal_Int32* pDeltaArray )
+                          const sal_Int32* pDeltaArray,
+                          const sal_Bool bUseGlyphs)
 {
     sal_uChar *pGlyphID    = (sal_uChar*)alloca (nLen * sizeof(sal_uChar));
     sal_Int32 *pGlyphSetID = (sal_Int32*)alloca (nLen * sizeof(sal_Int32));
@@ -488,7 +489,10 @@ void GlyphSet::DrawGlyphs(
     // convert unicode to font glyph id and font subset
     for (int nChar = 0; nChar < nLen; nChar++)
     {
-        GetGlyphID (pGlyphIds[nChar], pUnicodes[nChar], pGlyphID + nChar, pGlyphSetID + nChar);
+        if (bUseGlyphs)
+            GetGlyphID (pGlyphIds[nChar], pUnicodes[nChar], pGlyphID + nChar, pGlyphSetID + nChar);
+        else
+            GetCharID (pUnicodes[nChar], pGlyphID + nChar, pGlyphSetID + nChar);
         aGlyphSet.insert (pGlyphSetID[nChar]);
     }
 
@@ -536,7 +540,12 @@ void GlyphSet::DrawGlyphs(
         // show the text using the PrinterGfx text api
         aPoint.Move (nOffset, 0);
 
-        OString aGlyphSetName(GetGlyphSetName(*aSet));
+        OString aGlyphSetName;
+        if (bUseGlyphs)
+            aGlyphSetName = GetGlyphSetName(*aSet);
+        else
+            aGlyphSetName = GetCharSetName(*aSet);
+
         rGfx.PSSetFont  (aGlyphSetName, GetGlyphSetEncoding(*aSet));
         rGfx.PSMoveTo   (aPoint);
         rGfx.PSShowText (pGlyphSubset, nGlyphs, nGlyphs, nGlyphs > 1 ? pDeltaSubset : NULL);
@@ -614,66 +623,7 @@ GlyphSet::ImplDrawText (PrinterGfx &rGfx, const Point& rPoint,
         return;
     }
 
-    sal_uChar *pGlyphID    = (sal_uChar*)alloca (nLen * sizeof(sal_uChar));
-    sal_Int32 *pGlyphSetID = (sal_Int32*)alloca (nLen * sizeof(sal_Int32));
-    std::set< sal_Int32 > aGlyphSet;
-
-    // convert unicode to font glyph id and font subset
-    for (int nChar = 0; nChar < nLen; nChar++)
-    {
-        GetCharID (pStr[nChar], pGlyphID + nChar, pGlyphSetID + nChar);
-        aGlyphSet.insert (pGlyphSetID[nChar]);
-    }
-
-    // loop over all glyph sets to detect substrings that can be xshown together
-    // without changing the postscript font
-    sal_Int32 *pDeltaSubset = (sal_Int32*)alloca (nLen * sizeof(sal_Int32));
-    sal_uChar *pGlyphSubset = (sal_uChar*)alloca (nLen * sizeof(sal_uChar));
-
-    std::set< sal_Int32 >::iterator aSet;
-    for (aSet = aGlyphSet.begin(); aSet != aGlyphSet.end(); ++aSet)
-    {
-        Point     aPoint  = rPoint;
-        sal_Int32 nOffset = 0;
-        sal_Int32 nGlyphs = 0;
-        sal_Int32 nChar;
-
-        // get offset to first glyph
-        for (nChar = 0; (nChar < nLen) && (pGlyphSetID[nChar] != *aSet); nChar++)
-        {
-            nOffset = pDeltaArray [nChar];
-        }
-
-        // loop over all chars to extract those that share the current glyph set
-        for (nChar = 0; nChar < nLen; nChar++)
-        {
-            if (pGlyphSetID[nChar] == *aSet)
-            {
-                pGlyphSubset [nGlyphs] = pGlyphID [nChar];
-                // the offset to the next glyph is determined by the glyph in
-                // front of the next glyph with the same glyphset id
-                // most often, this will be the current glyph
-                while ((nChar + 1) < nLen)
-                {
-                    if (pGlyphSetID[nChar + 1] == *aSet)
-                        break;
-                    else
-                        nChar += 1;
-                }
-                pDeltaSubset [nGlyphs] = pDeltaArray[nChar] - nOffset;
-
-                nGlyphs += 1;
-            }
-        }
-
-        // show the text using the PrinterGfx text api
-        aPoint.Move (nOffset, 0);
-
-        OString aGlyphSetName(GetCharSetName(*aSet));
-        rGfx.PSSetFont  (aGlyphSetName, GetGlyphSetEncoding(*aSet));
-        rGfx.PSMoveTo   (aPoint);
-        rGfx.PSShowText (pGlyphSubset, nGlyphs, nGlyphs, nGlyphs > 1 ? pDeltaSubset : NULL);
-    }
+    DrawGlyphs( rGfx, rPoint, NULL, pStr, nLen, pDeltaArray, sal_False);
 }
 
 sal_Bool
diff --git a/vcl/generic/print/glyphset.hxx b/vcl/generic/print/glyphset.hxx
index d2d5a3f..1d6eb6f 100644
--- a/vcl/generic/print/glyphset.hxx
+++ b/vcl/generic/print/glyphset.hxx
@@ -121,7 +121,8 @@ public:
                                 const sal_uInt32* pGlyphIds,
                                 const sal_Unicode* pUnicodes,
                                 sal_Int16 nLen,
-                                const sal_Int32* pDeltaArray );
+                                const sal_Int32* pDeltaArray,
+                                sal_Bool bUseGlyphs=sal_True);
     sal_Bool        PSUploadEncoding(osl::File* pOutFile, PrinterGfx &rGfx);
     sal_Bool        PSUploadFont (osl::File& rOutFile, PrinterGfx &rGfx, bool bAsType42, 
std::list< rtl::OString >& rSuppliedFonts );
 };
-- 
1.7.4.1


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.