diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2016-12-08 04:13:26 +0200 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2016-12-10 02:03:48 +0000 |
commit | b157b82a6d924ebed1683b90bc9d59bbe2603451 (patch) | |
tree | 8e594207b05ce916dddf0f66fc2d1ed6b9e40cca /vcl | |
parent | bebee55d197176f009668628de0d9945c26af8ad (diff) |
Use GlyphItem in more places
Also simplify code to what is actually being used.
Change-Id: Ic640ea7f3e426e3f5f4f9fef30d774fe5ac111ff
Reviewed-on: https://gerrit.libreoffice.org/31815
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Khaled Hosny <khaledhosny@eglug.org>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/unx/printergfx.hxx | 22 | ||||
-rw-r--r-- | vcl/unx/generic/print/common_gfx.cxx | 61 | ||||
-rw-r--r-- | vcl/unx/generic/print/genpspgraphics.cxx | 4 | ||||
-rw-r--r-- | vcl/unx/generic/print/glyphset.cxx | 130 | ||||
-rw-r--r-- | vcl/unx/generic/print/glyphset.hxx | 15 | ||||
-rw-r--r-- | vcl/unx/generic/print/text_gfx.cxx | 125 |
6 files changed, 72 insertions, 285 deletions
diff --git a/vcl/inc/unx/printergfx.hxx b/vcl/inc/unx/printergfx.hxx index 871469e8d567..cb9a6c8f355a 100644 --- a/vcl/inc/unx/printergfx.hxx +++ b/vcl/inc/unx/printergfx.hxx @@ -249,21 +249,16 @@ public: void PSLineTo(const Point& rPoint ); void PSPointOp (const Point& rPoint, const sal_Char* pOperator); void PSHexString (const unsigned char* pString, sal_Int16 nLen); - void PSDeltaArray (const sal_Int32 *pArray, sal_Int16 nEntries); - void PSShowText (const unsigned char* pString, - sal_Int16 nGlyphs, sal_Int16 nBytes, - const sal_Int32* pDeltaArray = nullptr); + void PSShowGlyph (const unsigned char nGlyphId); void PSComment (const sal_Char* pComment ); void OnEndJob (); void writeResources( osl::File* pFile, std::list< OString >& rSuppliedFonts ); PrintFontManager& GetFontMgr () { return mrFontMgr; } - void drawGlyphs( const Point& rPoint, - sal_GlyphId* pGlyphIds, - sal_Unicode* pUnicodes, - sal_Int16 nLen, - sal_Int32* pDeltaArray ); + void drawGlyph(const Point& rPoint, + sal_GlyphId aGlyphId, + sal_Int32 nDelta); public: PrinterGfx(); ~PrinterGfx(); @@ -343,12 +338,9 @@ public: void SetTextColor (PrinterColor& rTextColor) { maTextColor = rTextColor; } - // for CTL - void DrawGlyphs( const Point& rPoint, - sal_GlyphId* pGlyphIds, - sal_Unicode* pUnicodes, - sal_Int16 nLen, - sal_Int32* pDeltaArray ); + void DrawGlyph(const Point& rPoint, + const GlyphItem& rGlyph, + sal_Int32 nDelta); }; diff --git a/vcl/unx/generic/print/common_gfx.cxx b/vcl/unx/generic/print/common_gfx.cxx index 793bd3cc19c4..d8b199b708b4 100644 --- a/vcl/unx/generic/print/common_gfx.cxx +++ b/vcl/unx/generic/print/common_gfx.cxx @@ -1012,39 +1012,8 @@ PrinterGfx::PSHexString (const unsigned char* pString, sal_Int16 nLen) WritePS (mpPageBody, pHexString, nChar); } -/* psshowtext helper routines: draw an array for xshow ps operator */ void -PrinterGfx::PSDeltaArray (const sal_Int32 *pArray, sal_Int16 nEntries) -{ - sal_Char pPSArray [128]; - sal_Int32 nChar = 0; - - nChar = psp::appendStr ("[", pPSArray + nChar); - nChar += psp::getValueOf (pArray[0], pPSArray + nChar); - - for (int i = 1; i < nEntries; i++) - { - if (nChar >= (nMaxTextColumn - 1)) - { - nChar += psp::appendStr ("\n", pPSArray + nChar); - WritePS (mpPageBody, pPSArray, nChar); - nChar = 0; - } - - nChar += psp::appendStr (" ", pPSArray + nChar); - nChar += psp::getValueOf (pArray[i] - pArray[i-1], pPSArray + nChar); - } - - nChar += psp::appendStr (" 0]\n", pPSArray + nChar); - WritePS (mpPageBody, pPSArray, nChar); -} - -/* the DrawText equivalent, pDeltaArray may be NULL. For Type1 fonts or single byte - * fonts in general nBytes and nGlyphs is the same. For printer resident Composite - * fonts it may be different (these fonts may be SJIS encoded for example) */ -void -PrinterGfx::PSShowText (const unsigned char* pStr, sal_Int16 nGlyphs, sal_Int16 nBytes, - const sal_Int32* pDeltaArray) +PrinterGfx::PSShowGlyph (const unsigned char nGlyphId) { PSSetColor (maTextColor); PSSetColor (); @@ -1066,31 +1035,17 @@ PrinterGfx::PSShowText (const unsigned char* pStr, sal_Int16 nGlyphs, sal_Int16 nLW = nLW < maVirtualStatus.mnTextHeight ? nLW : maVirtualStatus.mnTextHeight; psp::getValueOfDouble( pBuffer, (double)nLW / 30.0 ); } + // dispatch to the drawing method - if (pDeltaArray == nullptr) - { - PSHexString (pStr, nBytes); + PSHexString (&nGlyphId, 1); - if( maVirtualStatus.mbArtBold ) - { - WritePS( mpPageBody, pBuffer ); - WritePS( mpPageBody, " bshow\n" ); - } - else - WritePS (mpPageBody, "show\n"); - } - else + if( maVirtualStatus.mbArtBold ) { - PSHexString (pStr, nBytes); - PSDeltaArray (pDeltaArray, nGlyphs - 1); - if( maVirtualStatus.mbArtBold ) - { - WritePS( mpPageBody, pBuffer ); - WritePS( mpPageBody, " bxshow\n" ); - } - else - WritePS (mpPageBody, "xshow\n"); + WritePS( mpPageBody, pBuffer ); + WritePS( mpPageBody, " bshow\n" ); } + else + WritePS (mpPageBody, "show\n"); // restore the user coordinate system if (mnTextAngle != 0) diff --git a/vcl/unx/generic/print/genpspgraphics.cxx b/vcl/unx/generic/print/genpspgraphics.cxx index f0859eb11f1d..97fadbdba826 100644 --- a/vcl/unx/generic/print/genpspgraphics.cxx +++ b/vcl/unx/generic/print/genpspgraphics.cxx @@ -596,10 +596,8 @@ void GenPspGraphics::DrawTextLayout(const CommonSalLayout& rLayout) int nStart = 0; while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nStart)) { - sal_GlyphId aGlyphId = pGlyph->maGlyphId & (GF_IDXMASK | GF_ROTMASK); sal_Int32 nAdvance = pGlyph->mnNewWidth / rLayout.GetUnitsPerPixel(); - sal_Unicode nUnicode = 0; - m_pPrinterGfx->DrawGlyphs(aPos, &aGlyphId, &nUnicode, 1, &nAdvance); + m_pPrinterGfx->DrawGlyph(aPos, *pGlyph, nAdvance); } } diff --git a/vcl/unx/generic/print/glyphset.cxx b/vcl/unx/generic/print/glyphset.cxx index 7d8ee2edae56..3641fe160872 100644 --- a/vcl/unx/generic/print/glyphset.cxx +++ b/vcl/unx/generic/print/glyphset.cxx @@ -62,13 +62,12 @@ GlyphSet::~GlyphSet () bool GlyphSet::GetGlyphID ( sal_GlyphId nGlyph, - sal_Unicode nUnicode, unsigned char* nOutGlyphID, sal_Int32* nOutGlyphSetID ) { return LookupGlyphID (nGlyph, nOutGlyphID, nOutGlyphSetID) - || AddGlyphID (nGlyph, nUnicode, nOutGlyphID, nOutGlyphSetID); + || AddGlyphID (nGlyph, nOutGlyphID, nOutGlyphSetID); } bool @@ -102,17 +101,6 @@ GlyphSet::LookupGlyphID ( return false; } -unsigned char -GlyphSet::GetSymbolMapping (sal_Unicode nUnicodeChar) -{ - if (0x0000 < nUnicodeChar && nUnicodeChar < 0x0100) - return (unsigned char)nUnicodeChar; - if (0xf000 < nUnicodeChar && nUnicodeChar < 0xf100) - return (unsigned char)nUnicodeChar; - - return 0; -} - void GlyphSet::AddNotdef (glyph_map_t &rGlyphMap) { @@ -123,17 +111,10 @@ GlyphSet::AddNotdef (glyph_map_t &rGlyphMap) bool GlyphSet::AddGlyphID ( sal_GlyphId nGlyph, - sal_Unicode nUnicode, unsigned char* nOutGlyphID, sal_Int32* nOutGlyphSetID ) { - unsigned char nMappedChar = 0; - - // XXX important: avoid to reencode type1 symbol fonts - if (mnBaseEncoding == RTL_TEXTENCODING_SYMBOL) - nMappedChar = GetSymbolMapping (nUnicode); - // create an empty glyphmap that is reserved for unencoded symbol glyphs, // and a second map that takes any other if (maGlyphList.empty()) @@ -144,35 +125,20 @@ GlyphSet::AddGlyphID ( maGlyphList.push_back (aMapp); } // if the last map is full, create a new one - if ((!nMappedChar) && (maGlyphList.back().size() == 255)) + if (maGlyphList.back().size() == 255) { glyph_map_t aMap; maGlyphList.push_back (aMap); } - // insert a new glyph in the font subset - if (nMappedChar) - { - // always put symbol glyphs into the first map, map them on itself - glyph_map_t& aGlyphSet = maGlyphList.front(); - AddNotdef (aGlyphSet); + glyph_map_t& aGlyphSet = maGlyphList.back(); + AddNotdef (aGlyphSet); - aGlyphSet [nGlyph] = nMappedChar; - *nOutGlyphSetID = 1; - *nOutGlyphID = nMappedChar; - } - else - { - // other glyphs are just appended to the list - glyph_map_t& aGlyphSet = maGlyphList.back(); - AddNotdef (aGlyphSet); + int nSize = aGlyphSet.size(); - int nSize = aGlyphSet.size(); - - aGlyphSet [nGlyph] = nSize; - *nOutGlyphSetID = maGlyphList.size(); - *nOutGlyphID = aGlyphSet [nGlyph]; - } + aGlyphSet [nGlyph] = nSize; + *nOutGlyphSetID = maGlyphList.size(); + *nOutGlyphID = aGlyphSet [nGlyph]; return true; } @@ -211,76 +177,26 @@ GlyphSet::GetReencodedFontName (rtl_TextEncoding nEnc, const OString &rFontName) } } -void GlyphSet::DrawGlyphs( - PrinterGfx& rGfx, - const Point& rPoint, - const sal_GlyphId* pGlyphIds, - const sal_Unicode* pUnicodes, - sal_Int16 nLen, - const sal_Int32* pDeltaArray) +void GlyphSet::DrawGlyph(PrinterGfx& rGfx, + const Point& rPoint, + const sal_GlyphId nGlyphId, + const sal_Int32 nDelta) { - unsigned char *pGlyphID = static_cast<unsigned char*>(alloca (nLen * sizeof(unsigned char))); - sal_Int32 *pGlyphSetID = static_cast<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++) - { - GetGlyphID (pGlyphIds[nChar], pUnicodes[nChar], pGlyphID + nChar, pGlyphSetID + nChar); - aGlyphSet.insert (pGlyphSetID[nChar]); - } - - // loop over all glyph sets to detect substrings that can be shown together - // without changing the postscript font - sal_Int32 *pDeltaSubset = static_cast<sal_Int32*>(alloca (nLen * sizeof(sal_Int32))); - unsigned char *pGlyphSubset = static_cast<unsigned char*>(alloca (nLen * sizeof(unsigned char))); - - 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]; - } + unsigned char nGlyphID; + sal_Int32 nGlyphSetID; - // 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; - } - } + // convert to font glyph id and font subset + GetGlyphID (nGlyphId, &nGlyphID, &nGlyphSetID); - // show the text using the PrinterGfx text api - aPoint.Move (nOffset, 0); + // show the text using the PrinterGfx text api + Point aPoint = rPoint; + aPoint.Move (nDelta, 0); - OString aGlyphSetName; - aGlyphSetName = GetGlyphSetName(*aSet); + OString aGlyphSetName = GetGlyphSetName(nGlyphSetID); - rGfx.PSSetFont (aGlyphSetName, RTL_TEXTENCODING_DONTKNOW); - rGfx.PSMoveTo (aPoint); - rGfx.PSShowText (pGlyphSubset, nGlyphs, nGlyphs, nGlyphs > 1 ? pDeltaSubset : nullptr); - } + rGfx.PSSetFont (aGlyphSetName, RTL_TEXTENCODING_DONTKNOW); + rGfx.PSMoveTo (rPoint); + rGfx.PSShowGlyph(nGlyphID); } struct EncEntry diff --git a/vcl/unx/generic/print/glyphset.hxx b/vcl/unx/generic/print/glyphset.hxx index fccaacc9b91a..01ae3488c8d0 100644 --- a/vcl/unx/generic/print/glyphset.hxx +++ b/vcl/unx/generic/print/glyphset.hxx @@ -52,15 +52,14 @@ private: OString GetGlyphSetName (sal_Int32 nGlyphSetID); - bool GetGlyphID (sal_GlyphId nGlyphId, sal_Unicode nUnicode, + bool GetGlyphID (sal_GlyphId nGlyphId, unsigned char* nOutGlyphID, sal_Int32* nOutGlyphSetID); bool LookupGlyphID (sal_GlyphId nGlyphId, unsigned char* nOutGlyphID, sal_Int32* nOutGlyphSetID); - bool AddGlyphID (sal_GlyphId nGlyphId, sal_Unicode nUnicode, + bool AddGlyphID (sal_GlyphId nGlyphId, unsigned char* nOutGlyphID, sal_Int32* nOutGlyphSetID); static void AddNotdef (glyph_map_t &rGlyphMap); - static unsigned char GetSymbolMapping (sal_Unicode nUnicodeChar); public: @@ -76,12 +75,10 @@ public: const OString &rFontName); bool IsVertical () { return mbVertical;} - void DrawGlyphs (PrinterGfx& rGfx, - const Point& rPoint, - const sal_GlyphId* pGlyphIds, - const sal_Unicode* pUnicodes, - sal_Int16 nLen, - const sal_Int32* pDeltaArray); + void DrawGlyph (PrinterGfx& rGfx, + const Point& rPoint, + const sal_GlyphId nGlyphId, + const sal_Int32 nDelta); void PSUploadFont (osl::File& rOutFile, PrinterGfx &rGfx, bool bAsType42, std::list< OString >& rSuppliedFonts ); }; diff --git a/vcl/unx/generic/print/text_gfx.cxx b/vcl/unx/generic/print/text_gfx.cxx index bff561a2bd1c..2f04c72bc570 100644 --- a/vcl/unx/generic/print/text_gfx.cxx +++ b/vcl/unx/generic/print/text_gfx.cxx @@ -59,13 +59,9 @@ void PrinterGfx::SetFont( mbTextVertical = bVertical; } -void PrinterGfx::drawGlyphs( - const Point& rPoint, - sal_GlyphId* pGlyphIds, - sal_Unicode* pUnicodes, - sal_Int16 nLen, - sal_Int32* pDeltaArray - ) +void PrinterGfx::drawGlyph(const Point& rPoint, + sal_GlyphId aGlyphId, + sal_Int32 nDelta) { // draw the string @@ -75,7 +71,7 @@ void PrinterGfx::drawGlyphs( if ( ((*aIter).GetFontID() == mnFontID) && ((*aIter).IsVertical() == mbTextVertical)) { - (*aIter).DrawGlyphs (*this, rPoint, pGlyphIds, pUnicodes, nLen, pDeltaArray); + (*aIter).DrawGlyph (*this, rPoint, aGlyphId, nDelta); break; } @@ -83,21 +79,14 @@ void PrinterGfx::drawGlyphs( if (aIter == maPS3Font.end()) { maPS3Font.push_back (GlyphSet(mnFontID, mbTextVertical)); - maPS3Font.back().DrawGlyphs (*this, rPoint, pGlyphIds, pUnicodes, nLen, pDeltaArray); + maPS3Font.back().DrawGlyph (*this, rPoint, aGlyphId, nDelta); } } -void PrinterGfx::DrawGlyphs( - const Point& rPoint, - sal_GlyphId* pGlyphIds, - sal_Unicode* pUnicodes, - sal_Int16 nLen, - sal_Int32* pDeltaArray - ) +void PrinterGfx::DrawGlyph(const Point& rPoint, + const GlyphItem& rGlyph, + sal_Int32 nDelta) { - if( nLen <= 0 ) - return; - // move and rotate the user coordinate system // avoid the gsave/grestore for the simple cases since it allows // reuse of the current font if it hasn't changed @@ -113,17 +102,8 @@ void PrinterGfx::DrawGlyphs( aPoint = Point( 0, 0 ); } - if( mbTextVertical ) + if (mbTextVertical && (rGlyph.maGlyphId & GF_ROTMASK) != GF_NONE) { - // vertical glyphs can have an additional rotation ... sigh. - // so break up text in chunks of normal glyphs and print out - // specially rotated glyphs extra - sal_GlyphId* pTempGlyphIds = static_cast<sal_GlyphId*>(alloca(sizeof(sal_Int32)*nLen)); - sal_Int32* pTempDelta = static_cast<sal_Int32*>(alloca(sizeof(sal_Int32)*nLen)); - sal_Unicode* pTempUnicodes = static_cast<sal_Unicode*>(alloca(sizeof(sal_Unicode)*nLen)); - sal_Int16 nTempLen = 0; - sal_Int32 nTempFirstDelta = 0; - Point aRotPoint; sal_Int32 nTextHeight = maVirtualStatus.mnTextHeight; sal_Int32 nTextWidth = maVirtualStatus.mnTextWidth ? maVirtualStatus.mnTextWidth : maVirtualStatus.mnTextHeight; sal_Int32 nAscend = mrFontMgr.getFontAscend( mnFontID ); @@ -132,77 +112,26 @@ void PrinterGfx::DrawGlyphs( nDescend = nDescend * nTextHeight / 1000; nAscend = nAscend * nTextHeight / 1000; - for( sal_Int16 i = 0; i < nLen; i++ ) - { - const sal_GlyphId nRot = pGlyphIds[i] & GF_ROTMASK; - if( nRot == GF_NONE ) - { - pTempUnicodes[nTempLen] = pUnicodes[i]; - pTempGlyphIds[nTempLen] = pGlyphIds[i]; - if( nTempLen > 0 ) - pTempDelta[nTempLen-1] = pDeltaArray[i-1]-nTempFirstDelta; - else - { - // the first element in pDeltaArray shows - // the offset of the second character - // so if the first glyph is normal - // then we do not need to move the delta indices - // else we have to move them down by one and - // recalculate aPoint and all deltas - if( i != 0 ) - nTempFirstDelta = pDeltaArray[ i-1 ]; - } - nTempLen++; - } - else - { - sal_Int32 nOffset = i > 0 ? pDeltaArray[i-1] : 0; - sal_Int32 nRotAngle = 0; - switch( nRot ) - { - case GF_ROTR: - nRotAngle = 2700; - aRotPoint = Point( -nAscend*nTextWidth/nTextHeight, -nDescend*nTextWidth/nTextHeight - nOffset ); - break; - case GF_ROTL: - nRotAngle = 900; - aRotPoint = Point( -nDescend*nTextWidth/nTextHeight, nOffset + nAscend*nTextWidth/nTextHeight ); - break; - } - sal_GlyphId nRotGlyphId = pGlyphIds[i]; - sal_Unicode nRotUnicode = pUnicodes[i]; - sal_Int32 nRotDelta = 0; - - // transform matrix to new individual direction - PSGSave (); - GraphicsStatus aSaveStatus = maVirtualStatus; - if( nRot != 2 ) // switch font aspect - { - maVirtualStatus.mnTextWidth = nTextHeight; - maVirtualStatus.mnTextHeight = nTextWidth; - } - if( aPoint.X() || aPoint.Y() ) - PSTranslate( aPoint ); - PSRotate (nRotAngle); - // draw the rotated glyph - drawGlyphs( aRotPoint, &nRotGlyphId, &nRotUnicode, 1, &nRotDelta ); - - // restore previous state - maVirtualStatus = aSaveStatus; - PSGRestore(); - } - } - - pGlyphIds = pTempGlyphIds; - pUnicodes = pTempUnicodes; - pDeltaArray = pTempDelta; - nLen = nTempLen; + Point aRotPoint = Point( -nDescend*nTextWidth/nTextHeight, nAscend*nTextWidth/nTextHeight ); - aPoint.X() += nTempFirstDelta; + // transform matrix to new individual direction + PSGSave (); + GraphicsStatus aSaveStatus = maVirtualStatus; + // switch font aspect + maVirtualStatus.mnTextWidth = nTextHeight; + maVirtualStatus.mnTextHeight = nTextWidth; + if( aPoint.X() || aPoint.Y() ) + PSTranslate( aPoint ); + PSRotate (900); + // draw the rotated glyph + drawGlyph(aRotPoint, rGlyph.maGlyphId, 0); + + // restore previous state + maVirtualStatus = aSaveStatus; + PSGRestore(); } - - if( nLen > 0 ) - drawGlyphs( aPoint, pGlyphIds, pUnicodes, nLen, pDeltaArray ); + else + drawGlyph(aPoint, rGlyph.maGlyphId, nDelta); // restore the user coordinate system if (nCurrentTextAngle != 0) |