vcl/Library_vcl.mk | 6 vcl/inc/fontsubset.hxx | 5 vcl/inc/jobdata.hxx | 2 vcl/inc/sft.hxx | 47 vcl/inc/unx/printergfx.hxx | 346 ------ vcl/inc/unx/printerjob.hxx | 129 -- vcl/source/fontsubset/fontsubset.cxx | 63 - vcl/source/fontsubset/sft.cxx | 710 ------------ vcl/unx/generic/print/bitmap_gfx.cxx | 674 ------------ vcl/unx/generic/print/common_gfx.cxx | 1152 --------------------- vcl/unx/generic/print/glyphset.cxx | 297 ----- vcl/unx/generic/print/glyphset.hxx | 81 - vcl/unx/generic/print/printerjob.cxx | 969 ----------------- vcl/unx/generic/print/psputil.cxx | 184 --- vcl/unx/generic/print/psputil.hxx | 55 - vcl/unx/generic/print/text_gfx.cxx | 158 -- vcl/unx/generic/printer/configuration/psprint.conf | 5 vcl/unx/generic/printer/jobdata.cxx | 12 vcl/unx/generic/printer/printerinfomanager.cxx | 8 19 files changed, 2 insertions(+), 4901 deletions(-)
New commits: commit 3a01df55db376ecbed0d89ebb4dd9d2d2f4b520f Author: Khaled Hosny <kha...@libreoffice.org> AuthorDate: Sun Jul 30 14:23:58 2023 +0000 Commit: خالد حسني <kha...@libreoffice.org> CommitDate: Sun Jul 30 20:45:12 2023 +0200 Drop freshly unused font subsetting code These output font formats were for PostScript that is now gone. Change-Id: Ib29f921fe25432aaa558ba842ee77fe1e8023d47 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155069 Reviewed-by: خالد حسني <kha...@libreoffice.org> Tested-by: خالد حسني <kha...@libreoffice.org> diff --git a/vcl/inc/fontsubset.hxx b/vcl/inc/fontsubset.hxx index a1ba31aa58d8..1b218ed2e389 100644 --- a/vcl/inc/fontsubset.hxx +++ b/vcl/inc/fontsubset.hxx @@ -38,8 +38,6 @@ enum class FontType { TYPE1_PFA = 1<<3, ///< PSType1 Postscript Font Ascii TYPE1_PFB = 1<<4, ///< PSType1 Postscript Font Binary CFF_FONT = 1<<5, ///< CFF-container with PSType2 glyphs - TYPE3_FONT = 1<<6, ///< PSType3 Postscript font - TYPE42_FONT = 1<<7, ///< PSType42 wrapper for an SFNT_TTF ANY_SFNT = SFNT_TTF | SFNT_CFF, ANY_TYPE1 = TYPE1_PFA | TYPE1_PFB }; @@ -55,7 +53,6 @@ public: void LoadFont( FontType eInFontType, const unsigned char* pFontBytes, int nByteLength ); - void LoadFont( vcl::TrueTypeFont* pSftTrueTypeFont ); bool CreateFontSubset( FontType nOutFontTypeMask, SvStream* pOutFile, const char* pOutFontName, @@ -77,7 +74,6 @@ private: unsigned const char* mpInFontBytes; int mnInByteLength; FontType meInFontType; ///< allowed mask of input font-types - vcl::TrueTypeFont* mpSftTTFont; // subset-request details FontType mnReqFontTypeMask; ///< allowed subset-target font types @@ -88,7 +84,6 @@ private: int mnReqGlyphCount; bool CreateFontSubsetFromCff(); - bool CreateFontSubsetFromSfnt(); }; int VCL_DLLPUBLIC TestFontSubset(const void* data, sal_uInt32 size); diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx index b5fc71b44530..339914e4fb73 100644 --- a/vcl/inc/sft.hxx +++ b/vcl/inc/sft.hxx @@ -61,7 +61,7 @@ namespace vcl typedef sal_Int32 F16Dot16; /**< fixed: 16.16 */ /*@}*/ -/** Return value of OpenTTFont() and CreateT3FromTTGlyphs() */ +/** Return value of OpenTTFont() */ enum class SFErrCodes { Ok, /**< no error */ BadFile, /**< file not found */ @@ -565,25 +565,6 @@ class TrueTypeFont; void GetTTNameRecords(AbstractTrueTypeFont const *ttf, std::vector<NameRecord>& nr); -/** - * Generates a new PostScript Type 3 font and dumps it to <b>outf</b> file. - * This function substitutes glyph 0 for all glyphIDs that are not found in the font. - * @param ttf pointer to the TrueTypeFont structure - * @param outf the resulting font is written to this stream - * @param fname font name for the new font. If it is NULL the PostScript name of the - * original font will be used - * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf - * @param encoding array of encoding values. encoding[i] specifies the position of the glyph - * glyphArray[i] in the encoding vector of the resulting Type3 font - * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding - * @param wmode writing mode for the output file: 0 - horizontal, 1 - vertical - * @return return the value of SFErrCodes enum - * @see SFErrCodes - * @ingroup sft - * - */ - SFErrCodes CreateT3FromTTGlyphs(TrueTypeFont *ttf, SvStream *outf, const char *fname, sal_uInt16 const *glyphArray, sal_uInt8 *encoding, int nGlyphs, int wmode); - /** * Generates a new TrueType font and dumps it to <b>outf</b> file. * This function substitutes glyph 0 for all glyphIDs that are not found in the font. @@ -612,32 +593,6 @@ class TrueTypeFont; const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncoding, int nGlyphCount, FontSubsetInfo& rInfo); -/** - * Generates a new PostScript Type42 font and dumps it to <b>outf</b> file. - * This function substitutes glyph 0 for all glyphIDs that are not found in the font. - * @param ttf pointer to the TrueTypeFont structure - * @param outf output stream for a resulting font - * @param psname PostScript name of the resulting font - * @param glyphArray pointer to an array of glyphs that are to be extracted from ttf. The first - * element of this array has to be glyph 0 (default glyph) - * @param encoding array of encoding values. encoding[i] specifies character code for - * the glyphID glyphArray[i]. Character code 0 usually points to a default - * glyph (glyphID 0) - * @param nGlyphs number of glyph IDs in glyphArray and encoding values in encoding - * @return SFErrCodes::Ok - no errors - * SFErrCodes::GlyphNum - too many glyphs (> 255) - * SFErrCodes::TtFormat - corrupted TrueType fonts - * - * @see SFErrCodes - * @ingroup sft - * - */ - SFErrCodes CreateT42FromTTGlyphs(TrueTypeFont *ttf, - SvStream *outf, - const char *psname, - sal_uInt16 const *glyphArray, - sal_uInt8 *encoding, - int nGlyphs); /** * Returns global font information about the TrueType font. diff --git a/vcl/source/fontsubset/fontsubset.cxx b/vcl/source/fontsubset/fontsubset.cxx index 1ecd358727bf..2a45a1194e1a 100644 --- a/vcl/source/fontsubset/fontsubset.cxx +++ b/vcl/source/fontsubset/fontsubset.cxx @@ -33,7 +33,6 @@ FontSubsetInfo::FontSubsetInfo() , mpInFontBytes( nullptr) , mnInByteLength( 0) , meInFontType( FontType::NO_FONT) - , mpSftTTFont( nullptr) , mnReqFontTypeMask( FontType::NO_FONT ) , mpOutFile(nullptr) , mpReqFontName(nullptr) @@ -52,20 +51,11 @@ void FontSubsetInfo::LoadFont( FontType eInFontType, const unsigned char* pInFontBytes, int nInByteLength) { - SAL_WARN_IF( (mpSftTTFont != nullptr), "vcl", "Subset from SFT and from mapped font-file requested"); meInFontType = eInFontType; mpInFontBytes = pInFontBytes; mnInByteLength = nInByteLength; } -// prepare subsetting for fonts that are known to the SFT-parser -void FontSubsetInfo::LoadFont( vcl::TrueTypeFont* pSftTTFont ) -{ - SAL_WARN_IF( (mpInFontBytes != nullptr), "vcl", "Subset from SFT and from mapped font-file requested"); - mpSftTTFont = pSftTTFont; - meInFontType = FontType::ANY_SFNT; -} - bool FontSubsetInfo::CreateFontSubset( FontType nReqFontTypeMask, SvStream* pOutFile, const char* pReqFontName, @@ -90,18 +80,9 @@ bool FontSubsetInfo::CreateFontSubset( // TODO: better match available input-type to possible subset-types switch( meInFontType) { - case FontType::SFNT_TTF: - case FontType::SFNT_CFF: - case FontType::ANY_SFNT: - bOK = CreateFontSubsetFromSfnt(); - break; case FontType::CFF_FONT: bOK = CreateFontSubsetFromCff(); break; - case FontType::TYPE1_PFA: - case FontType::TYPE1_PFB: - case FontType::ANY_TYPE1: - case FontType::NO_FONT: default: OSL_FAIL( "unhandled type in CreateFontSubset()"); break; @@ -110,48 +91,4 @@ bool FontSubsetInfo::CreateFontSubset( return bOK; } -// TODO: move function to sft.cxx to replace dummy implementation -bool FontSubsetInfo::CreateFontSubsetFromSfnt() -{ - // handle SFNT_CFF fonts - sal_uInt32 nCffLength = 0; - const sal_uInt8* pCffBytes = mpSftTTFont->table(vcl::O_CFF, nCffLength); - if (pCffBytes) - { - LoadFont( FontType::CFF_FONT, pCffBytes, nCffLength); - const bool bOK = CreateFontSubsetFromCff(); - return bOK; - } - - // handle SFNT_TTF fonts - // by forwarding the subset request to AG's sft subsetter -#if 1 // TODO: remove conversion tp 16bit glyphids when sft-subsetter has been updated - std::vector<sal_uInt16> aShortGlyphIds; - aShortGlyphIds.reserve(mnReqGlyphCount); - for (int i = 0; i < mnReqGlyphCount; ++i) - aShortGlyphIds.push_back(static_cast<sal_uInt16>(mpReqGlyphIds[i])); - // remove const_cast when sft-subsetter is const-correct - sal_uInt8* pEncArray = const_cast<sal_uInt8*>( mpReqEncodedIds ); -#endif - vcl::SFErrCodes nSFTErr = vcl::SFErrCodes::BadArg; - if( mnReqFontTypeMask & FontType::TYPE42_FONT ) - { - nSFTErr = CreateT42FromTTGlyphs( mpSftTTFont, mpOutFile, mpReqFontName, - aShortGlyphIds.data(), pEncArray, mnReqGlyphCount ); - } - else if( mnReqFontTypeMask & FontType::TYPE3_FONT ) - { - nSFTErr = CreateT3FromTTGlyphs( mpSftTTFont, mpOutFile, mpReqFontName, - aShortGlyphIds.data(), pEncArray, mnReqGlyphCount, - 0 /* 0 = horizontal, 1 = vertical */ ); - } - else if( mnReqFontTypeMask & FontType::SFNT_TTF ) - { - // TODO: use CreateTTFromTTGlyphs() - // TODO: move functionality from callers here - } - - return (nSFTErr != vcl::SFErrCodes::Ok); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index 0eee2fee38b8..d34095d25d71 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -58,46 +58,8 @@ namespace vcl { -/*- module identification */ - -const char * const modname = "SunTypeTools-TT"; -const char * const modver = "1.0"; -const char * const modextra = "gelf"; - -/*- private functions, constants and data types */ - namespace { -enum PathSegmentType { - PS_NOOP = 0, - PS_MOVETO = 1, - PS_LINETO = 2, - PS_CURVETO = 3, - PS_CLOSEPATH = 4 -}; - -struct PSPathElement -{ - PathSegmentType type; - int x1, y1; - int x2, y2; - int x3, y3; - - explicit PSPathElement( PathSegmentType i_eType ) : type( i_eType ), - x1( 0 ), y1( 0 ), - x2( 0 ), y2( 0 ), - x3( 0 ), y3( 0 ) - { - } - - PSPathElement() : type( PS_NOOP ), - x1( 0 ), y1( 0 ), - x2( 0 ), y2( 0 ), - x3( 0 ), y3( 0 ) - { - } -}; - /*- In horizontal writing mode right sidebearing is calculated using this formula *- rsb = aw - (lsb + xMax - xMin) -*/ struct TTGlyphMetrics { @@ -110,34 +72,6 @@ struct TTGlyphMetrics { sal_uInt16 ah; /*- advance height (vertical writing mode) */ }; -constexpr int HFORMAT_LINELEN = 64; - -class HexFmt { -public: - HexFmt(SvStream *outf) : o(outf) {} - ~HexFmt() - { - Flush(); - } - bool Flush(); - void OpenString(); - void CloseString(); - void BlockWrite(const void *ptr, sal_uInt32 size); - -private: - SvStream *o; - char buffer[HFORMAT_LINELEN]; - size_t bufpos = 0; - int total = 0; -}; - -class GlyphOffsets { -public: - GlyphOffsets(sal_uInt8 *sfntP, sal_uInt32 sfntLen); - sal_uInt32 nGlyphs; /* number of glyphs in the font + 1 */ - std::unique_ptr<sal_uInt32[]> offs; /* array of nGlyphs offsets */ -}; - } /*- Data access methods for data stored in big-endian format */ @@ -207,58 +141,6 @@ static int XUnits(int unitsPerEm, int n) return (n * 1000) / unitsPerEm; } -static char toHex(sal_uInt8 nIndex) -{ - /* Hex Formatter functions */ - static const char HexChars[] = "0123456789ABCDEF"; - assert(nIndex < SAL_N_ELEMENTS(HexChars)); - return HexChars[nIndex]; -} - -bool HexFmt::Flush() -{ - bool bRet = true; - if (bufpos) { - size_t nWritten = o->WriteBytes(buffer, bufpos); - bRet = nWritten == bufpos; - bufpos = 0; - } - return bRet; -} - -void HexFmt::OpenString() -{ - o->WriteOString("<\n"); -} - -void HexFmt::CloseString() -{ - Flush(); - o->WriteOString("00\n>\n"); -} - -void HexFmt::BlockWrite(const void *ptr, sal_uInt32 size) -{ - if (total + size > 65534) { - Flush(); - CloseString(); - total = 0; - OpenString(); - } - - for (sal_uInt32 i = 0; i < size; ++i) { - sal_uInt8 Ch = static_cast<sal_uInt8 const *>(ptr)[i]; - buffer[bufpos++] = toHex(Ch >> 4); - buffer[bufpos++] = toHex(Ch & 0xF); - if (bufpos == HFORMAT_LINELEN) { - Flush(); - o->WriteOString("\n"); - } - - } - total += size; -} - /* Outline Extraction functions */ /* fills the aw and lsb entries of the TTGlyphMetrics structure from hmtx table -*/ @@ -742,133 +624,6 @@ static int GetTTGlyphOutline(AbstractTrueTypeFont *ttf, sal_uInt32 glyphID, std: return res; } -/*- returns the number of items in the path -*/ - -static int BSplineToPSPath(ControlPoint const *srcA, int srcCount, std::unique_ptr<PSPathElement[]>& path) -{ - std::vector< PSPathElement > aPathList; - int nPathCount = 0; - PSPathElement p( PS_NOOP ); - - int x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2, y2, curx, cury; - bool lastOff = false; /*- last point was off-contour */ - int scflag = 1; /*- start contour flag */ - bool ecflag = false; /*- end contour flag */ - int cp = 0; /*- current point */ - int StartContour = 0, EndContour = 1; - - path.reset(); - - /* if (srcCount > 0) for(;;) */ - while (srcCount > 0) { /*- srcCount does not get changed inside the loop. */ - if (scflag) { - int l = cp; - StartContour = cp; - while (!(srcA[l].flags & 0x8000)) l++; - EndContour = l; - if (StartContour == EndContour) { - if (cp + 1 < srcCount) { - cp++; - continue; - } else { - break; - } - } - p = PSPathElement(PS_MOVETO); - if (!(srcA[cp].flags & 1)) { - if (!(srcA[EndContour].flags & 1)) { - p.x1 = x0 = (srcA[cp].x + srcA[EndContour].x + 1) / 2; - p.y1 = y0 = (srcA[cp].y + srcA[EndContour].y + 1) / 2; - } else { - p.x1 = x0 = srcA[EndContour].x; - p.y1 = y0 = srcA[EndContour].y; - } - } else { - p.x1 = x0 = srcA[cp].x; - p.y1 = y0 = srcA[cp].y; - cp++; - } - aPathList.push_back( p ); - lastOff = false; - scflag = 0; - } - - curx = srcA[cp].x; - cury = srcA[cp].y; - - if (srcA[cp].flags & 1) - { - if (lastOff) - { - p = PSPathElement(PS_CURVETO); - p.x1 = x0 + (2 * (x1 - x0) + 1) / 3; - p.y1 = y0 + (2 * (y1 - y0) + 1) / 3; - p.x2 = x1 + (curx - x1 + 1) / 3; - p.y2 = y1 + (cury - y1 + 1) / 3; - p.x3 = curx; - p.y3 = cury; - aPathList.push_back( p ); - } - else - { - if (x0 != curx || y0 != cury) - { /* eliminate empty lines */ - p = PSPathElement(PS_LINETO); - p.x1 = curx; - p.y1 = cury; - aPathList.push_back( p ); - } - } - x0 = curx; y0 = cury; lastOff = false; - } - else - { - if (lastOff) - { - x2 = (x1 + curx + 1) / 2; - y2 = (y1 + cury + 1) / 2; - p = PSPathElement(PS_CURVETO); - p.x1 = x0 + (2 * (x1 - x0) + 1) / 3; - p.y1 = y0 + (2 * (y1 - y0) + 1) / 3; - p.x2 = x1 + (x2 - x1 + 1) / 3; - p.y2 = y1 + (y2 - y1 + 1) / 3; - p.x3 = x2; - p.y3 = y2; - aPathList.push_back( p ); - x0 = x2; y0 = y2; - x1 = curx; y1 = cury; - } else { - x1 = curx; y1 = cury; - } - lastOff = true; - } - - if (ecflag) { - aPathList.emplace_back(PS_CLOSEPATH ); - scflag = 1; - ecflag = false; - cp = EndContour + 1; - if (cp >= srcCount) break; - continue; - } - - if (cp == EndContour) { - cp = StartContour; - ecflag = true; - } else { - cp++; - } - } - - if( (nPathCount = static_cast<int>(aPathList.size())) > 0) - { - path.reset(new PSPathElement[nPathCount]); - memcpy( path.get(), aPathList.data(), nPathCount * sizeof(PSPathElement) ); - } - - return nPathCount; -} - /*- Extracts a string from the name table and allocates memory for it -*/ static OString nameExtract( const sal_uInt8* name, int nTableSize, int n, int dbFlag, OUString* ucs2result ) @@ -1561,188 +1316,6 @@ int GetTTGlyphComponents(AbstractTrueTypeFont *ttf, sal_uInt32 glyphID, std::vec return n; } -SFErrCodes CreateT3FromTTGlyphs(TrueTypeFont *ttf, SvStream *outf, const char *fname, - sal_uInt16 const *glyphArray, sal_uInt8 *encoding, int nGlyphs, - int wmode) -{ - std::vector<ControlPoint> pa; - std::unique_ptr<PSPathElement[]> path; - int i, j, n; - sal_uInt32 nSize; - const sal_uInt8* table = ttf->table(O_head, nSize); - TTGlyphMetrics metrics; - int UPEm = ttf->unitsPerEm(); - - const char * const h01 = "%%!PS-AdobeFont-%d.%d-%d.%d\n"; - const char * const h02 = "%% Creator: %s %s %s\n"; - const char * const h09 = "%% Original font name: %s\n"; - - const char * const h10 = - "30 dict begin\n" - "/PaintType 0 def\n" - "/FontType 3 def\n" - "/StrokeWidth 0 def\n"; - - const char * const h11 = "/FontName (%s) cvn def\n"; - - /* - const char *h12 = "%/UniqueID %d def\n"; - */ - const char * const h13 = "/FontMatrix [.001 0 0 .001 0 0] def\n"; - const char * const h14 = "/FontBBox [%d %d %d %d] def\n"; - - const char * const h15= - "/Encoding 256 array def\n" - " 0 1 255 {Encoding exch /.notdef put} for\n"; - - const char * const h16 = " Encoding %d /glyph%d put\n"; - const char * const h17 = "/XUID [103 0 0 16#%08" SAL_PRIXUINT32 " %d 16#%08" SAL_PRIXUINT32 " 16#%08" SAL_PRIXUINT32 "] def\n"; - - const char * const h30 = "/CharProcs %d dict def\n"; - const char * const h31 = " CharProcs begin\n"; - const char * const h32 = " /.notdef {} def\n"; - const char * const h33 = " /glyph%d {\n"; - const char * const h34 = " } bind def\n"; - const char * const h35 = " end\n"; - - const char * const h40 = - "/BuildGlyph {\n" - " exch /CharProcs get exch\n" - " 2 copy known not\n" - " {pop /.notdef} if\n" - " get exec\n" - "} bind def\n" - "/BuildChar {\n" - " 1 index /Encoding get exch get\n" - " 1 index /BuildGlyph get exec\n" - "} bind def\n" - "currentdict end\n"; - - const char * const h41 = "(%s) cvn exch definefont pop\n"; - - if ((nGlyphs <= 0) || (nGlyphs > 256)) return SFErrCodes::GlyphNum; - if (!glyphArray) return SFErrCodes::BadArg; - if (!fname) fname = ttf->psname.getStr(); - - constexpr int bufmax = 256; - char buf[bufmax]; - - snprintf(buf, bufmax, h01, GetInt16(table, 0), GetUInt16(table, 2), GetInt16(table, 4), GetUInt16(table, 6)); - outf->WriteOString(buf); - snprintf(buf, bufmax, h02, modname, modver, modextra); - outf->WriteOString(buf); - snprintf(buf, bufmax, h09, ttf->psname.getStr()); - outf->WriteOString(buf); - - snprintf(buf, bufmax, "%s", h10); - outf->WriteOString(buf); - snprintf(buf, bufmax, h11, fname); - outf->WriteOString(buf); -/* snprintf(buf, bufmax, h12, 4000000); */ - - /* XUID generation: - * 103 0 0 C1 C2 C3 C4 - * C1 - CRC-32 of the entire source TrueType font - * C2 - number of glyphs in the subset - * C3 - CRC-32 of the glyph array - * C4 - CRC-32 of the encoding array - * - * All CRC-32 numbers are presented as hexadecimal numbers - */ - - snprintf(buf, bufmax, h17, rtl_crc32(0, ttf->ptr, ttf->fsize), nGlyphs, rtl_crc32(0, glyphArray, nGlyphs * 2), rtl_crc32(0, encoding, nGlyphs)); - outf->WriteOString(buf); - snprintf(buf, bufmax, "%s", h13); - outf->WriteOString(buf); - snprintf(buf, bufmax, h14, XUnits(UPEm, GetInt16(table, 36)), XUnits(UPEm, GetInt16(table, 38)), XUnits(UPEm, GetInt16(table, 40)), XUnits(UPEm, GetInt16(table, 42))); - outf->WriteOString(buf); - snprintf(buf, bufmax, "%s", h15); - outf->WriteOString(buf); - - for (i = 0; i < nGlyphs; i++) { - snprintf(buf, bufmax, h16, encoding[i], i); - outf->WriteOString(buf); - } - - snprintf(buf, bufmax, h30, nGlyphs+1); - outf->WriteOString(buf); - snprintf(buf, bufmax, "%s", h31); - outf->WriteOString(buf); - snprintf(buf, bufmax, "%s", h32); - outf->WriteOString(buf); - - for (i = 0; i < nGlyphs; i++) { - snprintf(buf, bufmax, h33, i); - outf->WriteOString(buf); - int r = GetTTGlyphOutline(ttf, glyphArray[i] < ttf->glyphCount() ? glyphArray[i] : 0, pa, &metrics, nullptr); - - if (r > 0) { - n = BSplineToPSPath(pa.data(), r, path); - } else { - n = 0; /* glyph might have zero contours but valid metrics ??? */ - path = nullptr; - if (r < 0) { /* glyph is not present in the font - pa array was not allocated, so no need to free it */ - continue; - } - } - snprintf(buf, bufmax, "\t%d %d %d %d %d %d setcachedevice\n", - wmode == 0 ? XUnits(UPEm, metrics.aw) : 0, - wmode == 0 ? 0 : -XUnits(UPEm, metrics.ah), - XUnits(UPEm, metrics.xMin), - XUnits(UPEm, metrics.yMin), - XUnits(UPEm, metrics.xMax), - XUnits(UPEm, metrics.yMax)); - outf->WriteOString(buf); - - for (j = 0; j < n; j++) - { - switch (path[j].type) - { - case PS_MOVETO: - snprintf(buf, bufmax, "\t%d %d moveto\n", XUnits(UPEm, path[j].x1), XUnits(UPEm, path[j].y1)); - outf->WriteOString(buf); - break; - - case PS_LINETO: - snprintf(buf, bufmax, "\t%d %d lineto\n", XUnits(UPEm, path[j].x1), XUnits(UPEm, path[j].y1)); - outf->WriteOString(buf); - break; - - case PS_CURVETO: - snprintf(buf, bufmax, "\t%d %d %d %d %d %d curveto\n", XUnits(UPEm, path[j].x1), XUnits(UPEm, path[j].y1), XUnits(UPEm, path[j].x2), XUnits(UPEm, path[j].y2), XUnits(UPEm, path[j].x3), XUnits(UPEm, path[j].y3)); - outf->WriteOString(buf); - break; - - case PS_CLOSEPATH: - snprintf(buf, bufmax, "\tclosepath\n"); - outf->WriteOString(buf); - break; - case PS_NOOP: - break; - } - } - if (n > 0) - { - snprintf(buf, bufmax, "\tfill\n"); /* if glyph is not a whitespace character */ - outf->WriteOString(buf); - } - - snprintf(buf, bufmax, "%s", h34); - outf->WriteOString(buf); - - path.reset(); - } - snprintf(buf, bufmax, "%s", h35); - outf->WriteOString(buf); - - snprintf(buf, bufmax, "%s", h40); - outf->WriteOString(buf); - snprintf(buf, bufmax, h41, fname); - outf->WriteOString(buf); - - return SFErrCodes::Ok; -} - SFErrCodes CreateTTFromTTGlyphs(AbstractTrueTypeFont *ttf, std::vector<sal_uInt8>& rOutBuffer, sal_uInt16 const *glyphArray, @@ -1977,289 +1550,6 @@ bool CreateTTFfontSubset(vcl::AbstractTrueTypeFont& rTTF, std::vector<sal_uInt8> == vcl::SFErrCodes::Ok); } -GlyphOffsets::GlyphOffsets(sal_uInt8 *sfntP, sal_uInt32 sfntLen) -{ - sal_uInt8 *loca = nullptr; - sal_uInt16 numTables = GetUInt16(sfntP, 4); - sal_uInt32 locaLen = 0; - sal_Int16 indexToLocFormat = 0; - - sal_uInt32 nMaxPossibleTables = sfntLen / (3*sizeof(sal_uInt32)); /*the three GetUInt32 calls*/ - if (numTables > nMaxPossibleTables) - { - SAL_WARN( "vcl.fonts", "GlyphOffsetsNew claimed to have " - << numTables << " tables, but that's impossibly large"); - numTables = nMaxPossibleTables; - } - - for (sal_uInt16 i = 0; i < numTables; i++) { - sal_uInt32 nLargestFixedOffsetPos = 12 + 16 * i + 12; - sal_uInt32 nMinSize = nLargestFixedOffsetPos + sizeof(sal_uInt32); - if (nMinSize > sfntLen) - { - SAL_WARN( "vcl.fonts", "GlyphOffsetsNew claimed to have " - << numTables << " tables, but only space for " << i); - break; - } - - sal_uInt32 tag = GetUInt32(sfntP, 12 + 16 * i); - sal_uInt32 off = GetUInt32(sfntP, 12 + 16 * i + 8); - sal_uInt32 len = GetUInt32(sfntP, nLargestFixedOffsetPos); - - if (tag == T_loca) { - loca = sfntP + off; - locaLen = len; - } else if (tag == T_head) { - indexToLocFormat = GetInt16(sfntP + off, 50); - } - } - - this->nGlyphs = locaLen / ((indexToLocFormat == 1) ? 4 : 2); - assert(this->nGlyphs != 0); - this->offs = std::make_unique<sal_uInt32[]>(this->nGlyphs); - - for (sal_uInt32 i = 0; i < this->nGlyphs; i++) { - if (indexToLocFormat == 1) { - this->offs[i] = GetUInt32(loca, i * 4); - } else { - this->offs[i] = GetUInt16(loca, i * 2) << 1; - } - } -} - -static void DumpSfnts(SvStream *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen) -{ - if (sfntLen < 12) - { - SAL_WARN( "vcl.fonts", "DumpSfnts sfntLen is too short: " - << sfntLen << " legal min is: " << 12); - return; - } - - const sal_uInt32 nSpaceForTables = sfntLen - 12; - const sal_uInt32 nTableSize = 16; - const sal_uInt32 nMaxPossibleTables = nSpaceForTables/nTableSize; - - HexFmt h(outf); - sal_uInt16 i, numTables = GetUInt16(sfntP, 4); - GlyphOffsets go(sfntP, sfntLen); - sal_uInt8 const pad[] = {0,0,0,0}; /* zeroes */ - - if (numTables > nMaxPossibleTables) - { - SAL_WARN( "vcl.fonts", "DumpSfnts claimed to have " - << numTables << " tables, but only space for " << nMaxPossibleTables); - numTables = nMaxPossibleTables; - } - - assert(numTables <= 9); /* Type42 has 9 required tables */ - - std::unique_ptr<sal_uInt32[]> offs(new sal_uInt32[numTables]); - - outf->WriteOString("/sfnts ["); - h.OpenString(); - h.BlockWrite(sfntP, 12); /* stream out the Offset Table */ - h.BlockWrite(sfntP+12, 16 * numTables); /* stream out the Table Directory */ - - for (i=0; i<numTables; i++) - { - sal_uInt32 nLargestFixedOffsetPos = 12 + 16 * i + 12; - sal_uInt32 nMinSize = nLargestFixedOffsetPos + sizeof(sal_uInt32); - if (nMinSize > sfntLen) - { - SAL_WARN( "vcl.fonts", "DumpSfnts claimed to have " - << numTables << " tables, but only space for " << i); - break; - } - - sal_uInt32 tag = GetUInt32(sfntP, 12 + 16 * i); - sal_uInt32 off = GetUInt32(sfntP, 12 + 16 * i + 8); - if (off > sfntLen) - { - SAL_WARN( "vcl.fonts", "DumpSfnts claims offset of " - << off << " but max possible is " << sfntLen); - break; - } - sal_uInt8 *pRecordStart = sfntP + off; - sal_uInt32 len = GetUInt32(sfntP, nLargestFixedOffsetPos); - sal_uInt32 nMaxLenPossible = sfntLen - off; - if (len > nMaxLenPossible) - { - SAL_WARN( "vcl.fonts", "DumpSfnts claims len of " - << len << " but only space for " << nMaxLenPossible); - break; - } - - if (tag != T_glyf) - { - h.BlockWrite(pRecordStart, len); - } - else - { - sal_uInt8 *glyf = pRecordStart; - sal_uInt8 *eof = pRecordStart + nMaxLenPossible; - for (sal_uInt32 j = 0; j < go.nGlyphs - 1; j++) - { - sal_uInt32 nStartOffset = go.offs[j]; - sal_uInt8 *pSubRecordStart = glyf + nStartOffset; - if (pSubRecordStart > eof) - { - SAL_WARN( "vcl.fonts", "DumpSfnts start glyf claims offset of " - << pSubRecordStart - sfntP << " but max possible is " << eof - sfntP); - break; - } - - sal_uInt32 nEndOffset = go.offs[j + 1]; - sal_uInt8 *pSubRecordEnd = glyf + nEndOffset; - if (pSubRecordEnd > eof) - { - SAL_WARN( "vcl.fonts", "DumpSfnts end glyf offset of " - << pSubRecordEnd - sfntP << " but max possible is " << eof - sfntP); - break; - } - - sal_uInt32 l = pSubRecordEnd - pSubRecordStart; - h.BlockWrite(pSubRecordStart, l); - } - } - h.BlockWrite(pad, (4 - (len & 3)) & 3); - } - h.CloseString(); - outf->WriteOString("] def\n"); -} - -SFErrCodes CreateT42FromTTGlyphs(TrueTypeFont *ttf, - SvStream *outf, - const char *psname, - sal_uInt16 const *glyphArray, - sal_uInt8 *encoding, - int nGlyphs) -{ - std::unique_ptr<TrueTypeTable> head, hhea, maxp, cvt, prep, fpgm; - std::unique_ptr<TrueTypeTableGlyf> glyf; - int i; - SFErrCodes res; - - sal_uInt16 ver; - sal_Int32 rev; - - int UPEm = ttf->unitsPerEm(); - - if (nGlyphs >= 256) return SFErrCodes::GlyphNum; - - assert(psname != nullptr); - - TrueTypeCreator ttcr(T_true); - - /* head */ - sal_uInt32 nTableSize; - const sal_uInt8* p = ttf->table(O_head, nTableSize); - const sal_uInt8* headP = p; - assert(p != nullptr); - head.reset(new TrueTypeTableHead(GetInt32(p, HEAD_fontRevision_offset), GetUInt16(p, HEAD_flags_offset), GetUInt16(p, HEAD_unitsPerEm_offset), p+HEAD_created_offset, GetUInt16(p, HEAD_macStyle_offset), GetUInt16(p, HEAD_lowestRecPPEM_offset), GetInt16(p, HEAD_fontDirectionHint_offset))); - ver = GetUInt16(p, HEAD_majorVersion_offset); - rev = GetInt32(p, HEAD_fontRevision_offset); - - /** hhea **/ - p = ttf->table(O_hhea, nTableSize); - if (p) - hhea.reset(new TrueTypeTableHhea(GetInt16(p, HHEA_ascender_offset), GetInt16(p, HHEA_descender_offset), GetInt16(p, HHEA_lineGap_offset), GetInt16(p, HHEA_caretSlopeRise_offset), GetInt16(p, HHEA_caretSlopeRun_offset))); - else - hhea.reset(new TrueTypeTableHhea(0, 0, 0, 0, 0)); - - /** maxp **/ - p = ttf->table(O_maxp, nTableSize); - maxp.reset(new TrueTypeTableMaxp(p, nTableSize)); - - /** cvt **/ - if ((p = ttf->table(O_cvt, nTableSize)) != nullptr) - cvt.reset(new TrueTypeTableGeneric(T_cvt, nTableSize, p)); - - /** prep **/ - if ((p = ttf->table(O_prep, nTableSize)) != nullptr) - prep.reset(new TrueTypeTableGeneric(T_prep, nTableSize, p)); - - /** fpgm **/ - if ((p = ttf->table(O_fpgm, nTableSize)) != nullptr) - fpgm.reset(new TrueTypeTableGeneric(T_fpgm, nTableSize, p)); - - /** glyf **/ - glyf.reset(new TrueTypeTableGlyf()); - std::unique_ptr<sal_uInt16[]> gID(new sal_uInt16[nGlyphs]); - - for (i = 0; i < nGlyphs; i++) { - gID[i] = static_cast<sal_uInt16>(glyf->glyfAdd(GetTTRawGlyphData(ttf, glyphArray[i]), ttf)); - } - - const int nGlyfCount = static_cast<int>(glyf->glyfCount()); - - ttcr.AddTable(std::move(head)); ttcr.AddTable(std::move(hhea)); ttcr.AddTable(std::move(maxp)); ttcr.AddTable(std::move(cvt)); - ttcr.AddTable(std::move(prep)); ttcr.AddTable(std::move(glyf)); ttcr.AddTable(std::move(fpgm)); - - std::vector<sal_uInt8> aOutBuffer; - if ((res = ttcr.StreamToMemory(aOutBuffer)) != SFErrCodes::Ok) { - return res; - } - - constexpr int bufmax = 256; - char buf[bufmax]; - - snprintf(buf, bufmax, "%%!PS-TrueTypeFont-%d.%d-%d.%d\n", static_cast<int>(ver), static_cast<int>(ver & 0xFF), static_cast<int>(rev>>16), static_cast<int>(rev & 0xFFFF)); - outf->WriteOString(buf); - snprintf(buf, bufmax, "%%%%Creator: %s %s %s\n", modname, modver, modextra); - outf->WriteOString(buf); - snprintf(buf, bufmax, "%%- Font subset generated from a source font file: '%s'\n", ttf->fileName().data()); - outf->WriteOString(buf); - snprintf(buf, bufmax, "%%- Original font name: %s\n", ttf->psname.getStr()); - outf->WriteOString(buf); - snprintf(buf, bufmax, "%%- Original font family: %s\n", ttf->family.getStr()); - outf->WriteOString(buf); - snprintf(buf, bufmax, "%%- Original font sub-family: %s\n", ttf->subfamily.getStr()); - outf->WriteOString(buf); - snprintf(buf, bufmax, "11 dict begin\n"); - outf->WriteOString(buf); - snprintf(buf, bufmax, "/FontName (%s) cvn def\n", psname); - outf->WriteOString(buf); - snprintf(buf, bufmax, "/PaintType 0 def\n"); - outf->WriteOString(buf); - snprintf(buf, bufmax, "/FontMatrix [1 0 0 1 0 0] def\n"); - outf->WriteOString(buf); - snprintf(buf, bufmax, "/FontBBox [%d %d %d %d] def\n", XUnits(UPEm, GetInt16(headP, HEAD_xMin_offset)), XUnits(UPEm, GetInt16(headP, HEAD_yMin_offset)), XUnits(UPEm, GetInt16(headP, HEAD_xMax_offset)), XUnits(UPEm, GetInt16(headP, HEAD_yMax_offset))); - outf->WriteOString(buf); - snprintf(buf, bufmax, "/FontType 42 def\n"); - outf->WriteOString(buf); - snprintf(buf, bufmax, "/Encoding 256 array def\n"); - outf->WriteOString(buf); - snprintf(buf, bufmax, " 0 1 255 {Encoding exch /.notdef put} for\n"); - outf->WriteOString(buf); - - for (i = 1; i<nGlyphs; i++) { - snprintf(buf, bufmax, "Encoding %d /glyph%u put\n", encoding[i], gID[i]); - outf->WriteOString(buf); - } - snprintf(buf, bufmax, "/XUID [103 0 1 16#%08X %u 16#%08X 16#%08X] def\n", static_cast<unsigned int>(rtl_crc32(0, ttf->ptr, ttf->fsize)), static_cast<unsigned int>(nGlyphs), static_cast<unsigned int>(rtl_crc32(0, glyphArray, nGlyphs * 2)), static_cast<unsigned int>(rtl_crc32(0, encoding, nGlyphs))); - outf->WriteOString(buf); - - DumpSfnts(outf, aOutBuffer.data(), aOutBuffer.size()); - - /* dump charstrings */ - snprintf(buf, bufmax, "/CharStrings %d dict dup begin\n", nGlyphs); - outf->WriteOString(buf); - snprintf(buf, bufmax, "/.notdef 0 def\n"); - outf->WriteOString(buf); - for (i = 1; i < nGlyfCount; i++) { - snprintf(buf, bufmax, "/glyph%d %d def\n", i, i); - outf->WriteOString(buf); - } - snprintf(buf, bufmax, "end readonly def\n"); - outf->WriteOString(buf); - - snprintf(buf, bufmax, "FontName currentdict end definefont pop\n"); - outf->WriteOString(buf); - - return SFErrCodes::Ok; -} - bool GetTTGlobalFontHeadInfo(const AbstractTrueTypeFont *ttf, int& xMin, int& yMin, int& xMax, int& yMax, sal_uInt16& macStyle) { sal_uInt32 table_size; commit 984e2e78340c4818538f653e07f19acfc29646c5 Author: Khaled Hosny <kha...@libreoffice.org> AuthorDate: Sun Jul 30 14:22:46 2023 +0000 Commit: خالد حسني <kha...@libreoffice.org> CommitDate: Sun Jul 30 20:45:06 2023 +0200 tdf#156230: Drop freshly unused PSLevel setting Change-Id: I9331b5532f8066f7d13815487c7af0e7fd37e54f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155068 Tested-by: Jenkins Reviewed-by: خالد حسني <kha...@libreoffice.org> diff --git a/vcl/inc/jobdata.hxx b/vcl/inc/jobdata.hxx index ceb7a8bf739f..ae9db11e69f6 100644 --- a/vcl/inc/jobdata.hxx +++ b/vcl/inc/jobdata.hxx @@ -39,7 +39,6 @@ struct VCL_DLLPUBLIC JobData int m_nBottomMarginAdjust; // user overrides for PPD int m_nColorDepth; - int m_nPSLevel; // 0: no override, else languagelevel to use int m_nColorDevice; // 0: no override, -1 grey scale, +1 color orientation m_eOrientation; OUString m_aPrinterName; @@ -55,7 +54,6 @@ struct VCL_DLLPUBLIC JobData m_nTopMarginAdjust( 0 ), m_nBottomMarginAdjust( 0 ), m_nColorDepth( 24 ), - m_nPSLevel( 0 ), m_nColorDevice( 0 ), m_eOrientation( orientation::Portrait ), m_bPapersizeFromSetup( false ), diff --git a/vcl/unx/generic/printer/configuration/psprint.conf b/vcl/unx/generic/printer/configuration/psprint.conf index 1b56e084ea71..015a310d62bb 100644 --- a/vcl/unx/generic/printer/configuration/psprint.conf +++ b/vcl/unx/generic/printer/configuration/psprint.conf @@ -46,11 +46,6 @@ ; if key is absent the default is 0 ; ColorDepth=0 -; PSLevel: the default setting of the PostScript level of the output -; possible values: 0: driver setting, 1: level 1, 2: level2 -; if key is absent the default is 0 -; PSLevel=0 - ; PPD_PageSize: the default page size to use. If a specific printer does ; not support this page size its default is used instead. ; possible values: A0, A1, A2, A3, A4, A5, A6, B4, B5, B6, diff --git a/vcl/unx/generic/printer/jobdata.cxx b/vcl/unx/generic/printer/jobdata.cxx index bb2dded8938e..c53bf06f7041 100644 --- a/vcl/unx/generic/printer/jobdata.cxx +++ b/vcl/unx/generic/printer/jobdata.cxx @@ -45,7 +45,6 @@ JobData& JobData::operator=(const JobData& rRight) m_bPapersizeFromSetup = rRight.m_bPapersizeFromSetup; m_pParser = rRight.m_pParser; m_aContext = rRight.m_aContext; - m_nPSLevel = rRight.m_nPSLevel; m_nColorDevice = rRight.m_nColorDevice; if( !m_pParser && !m_aPrinterName.isEmpty() ) @@ -130,8 +129,6 @@ bool JobData::getStreamBuffer( void*& pData, sal_uInt32& bytes ) aStream.WriteLine(Concat2View("colordepth=" + OString::number(static_cast<sal_Int32>(m_nColorDepth)))); - aStream.WriteLine(Concat2View("pslevel=" + OString::number(static_cast<sal_Int32>(m_nPSLevel)))); - aStream.WriteLine(Concat2View("colordevice=" + OString::number(static_cast<sal_Int32>(m_nColorDevice)))); // now append the PPDContext stream buffer @@ -161,7 +158,6 @@ bool JobData::constructFromStreamBuffer( const void* pData, sal_uInt32 bytes, Jo bool bMargin = false; bool bColorDepth = false; bool bColorDevice = false; - bool bPSLevel = false; const char printerEquals[] = "printer="; const char orientatationEquals[] = "orientation="; @@ -170,7 +166,6 @@ bool JobData::constructFromStreamBuffer( const void* pData, sal_uInt32 bytes, Jo const char marginadjustmentEquals[] = "marginadjustment="; const char colordepthEquals[] = "colordepth="; const char colordeviceEquals[] = "colordevice="; - const char pslevelEquals[] = "pslevel="; while( ! aStream.eof() ) { @@ -215,11 +210,6 @@ bool JobData::constructFromStreamBuffer( const void* pData, sal_uInt32 bytes, Jo bColorDevice = true; rJobData.m_nColorDevice = o3tl::toInt32(aLine.subView(RTL_CONSTASCII_LENGTH(colordeviceEquals))); } - else if (aLine.startsWith(pslevelEquals)) - { - bPSLevel = true; - rJobData.m_nPSLevel = o3tl::toInt32(aLine.subView(RTL_CONSTASCII_LENGTH(pslevelEquals))); - } else if (aLine == "PPDContextData" && bPrinter) { PrinterInfoManager& rManager = PrinterInfoManager::get(); @@ -242,7 +232,7 @@ bool JobData::constructFromStreamBuffer( const void* pData, sal_uInt32 bytes, Jo } } - return bVersion && bPrinter && bOrientation && bCopies && bContext && bMargin && bPSLevel && bColorDevice && bColorDepth; + return bVersion && bPrinter && bOrientation && bCopies && bContext && bMargin && bColorDevice && bColorDepth; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/printer/printerinfomanager.cxx b/vcl/unx/generic/printer/printerinfomanager.cxx index 3957e3608cd2..473645a96b8a 100644 --- a/vcl/unx/generic/printer/printerinfomanager.cxx +++ b/vcl/unx/generic/printer/printerinfomanager.cxx @@ -240,10 +240,6 @@ void PrinterInfoManager::initialize() if (!aValue.isEmpty()) m_aGlobalDefaults.m_nColorDevice = aValue.toInt32(); - aValue = aConfig.ReadKey( "PSLevel" ); - if (!aValue.isEmpty()) - m_aGlobalDefaults.m_nPSLevel = aValue.toInt32(); - // get the PPDContext of global JobData for( int nKey = 0; nKey < aConfig.GetKeyCount(); ++nKey ) { @@ -420,10 +416,6 @@ void PrinterInfoManager::initialize() if (!aValue.isEmpty()) aPrinter.m_aInfo.m_nColorDevice = aValue.toInt32(); - aValue = aConfig.ReadKey( "PSLevel" ); - if (!aValue.isEmpty()) - aPrinter.m_aInfo.m_nPSLevel = aValue.toInt32(); - // now iterate over all keys to extract multi key information: // 1. PPDContext information for( int nKey = 0; nKey < aConfig.GetKeyCount(); ++nKey ) commit c106e5d95918f569bc2e45bec3792ddad6db99e4 Author: Khaled Hosny <kha...@libreoffice.org> AuthorDate: Sun Jul 30 11:36:11 2023 +0000 Commit: خالد حسني <kha...@libreoffice.org> CommitDate: Sun Jul 30 20:44:58 2023 +0200 tdf#156230: Drop freshly unused PrinterJob and PrinterGfx Change-Id: I5149fb447e76044e7f4bfdd9a79ee3b454859375 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155065 Tested-by: Jenkins Reviewed-by: خالد حسني <kha...@libreoffice.org> diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 6293e292b25e..c29801fe58a3 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -559,15 +559,9 @@ vcl_headless_freetype_code=\ vcl/unx/generic/fontmanager/fontconfig \ vcl/unx/generic/fontmanager/fontmanager \ vcl/unx/generic/fontmanager/helper \ - vcl/unx/generic/print/bitmap_gfx \ - vcl/unx/generic/print/common_gfx \ - vcl/unx/generic/print/glyphset \ - vcl/unx/generic/print/printerjob \ - vcl/unx/generic/print/psputil \ vcl/unx/generic/print/genpspgraphics \ vcl/unx/generic/print/genprnpsp \ vcl/unx/generic/print/prtsetup \ - vcl/unx/generic/print/text_gfx \ vcl/unx/generic/printer/jobdata \ vcl/unx/generic/printer/ppdparser \ diff --git a/vcl/inc/unx/printergfx.hxx b/vcl/inc/unx/printergfx.hxx deleted file mode 100644 index 0c89ef463bbf..000000000000 --- a/vcl/inc/unx/printergfx.hxx +++ /dev/null @@ -1,346 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX -#define INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX - -#include <osl/file.hxx> -#include <tools/gen.hxx> -#include <vcl/dllapi.h> - -#include <impglyphitem.hxx> - -#include <list> -#include <vector> - -enum class PolyFlags : sal_uInt8; - -namespace psp { - -struct JobData; - -/* - * lightweight container to handle RGB values - */ - -class PrinterColor -{ -public: - - enum class ColorSpace { eInvalid, eRGB }; - -private: - - sal_uInt8 mnRed; - sal_uInt8 mnGreen; - sal_uInt8 mnBlue; - ColorSpace meColorspace; - -public: - - PrinterColor() - : mnRed(0) - , mnGreen(0) - , mnBlue(0) - , meColorspace(ColorSpace::eInvalid) - {} - PrinterColor (sal_uInt16 nRed, sal_uInt16 nGreen, - sal_uInt16 nBlue) : - mnRed (nRed), - mnGreen (nGreen), - mnBlue (nBlue), - meColorspace (ColorSpace::eRGB) - {} - PrinterColor (sal_uInt32 nRGB) : - mnRed ((nRGB & 0x00ff0000) >> 16), - mnGreen ((nRGB & 0x0000ff00) >> 8), - mnBlue ((nRGB & 0x000000ff) ), - meColorspace (ColorSpace::eRGB) - {} - - bool Is () const - { return meColorspace != ColorSpace::eInvalid; } - - sal_uInt16 GetRed () const - { return mnRed; } - sal_uInt16 GetGreen () const - { return mnGreen; } - sal_uInt16 GetBlue () const - { return mnBlue; } - bool operator== (const PrinterColor& aColor) const - { - return aColor.Is() && Is() - && mnRed == aColor.mnRed - && mnGreen == aColor.mnGreen - && mnBlue == aColor.mnBlue; - } - bool operator!= (const PrinterColor& aColor) const - { return ! (aColor==*this); } - - PrinterColor& operator= (sal_uInt32 nRGB) - { - meColorspace = ColorSpace::eRGB; - mnBlue = (nRGB & 0x000000ff); - mnGreen = (nRGB & 0x0000ff00) >> 8; - mnRed = (nRGB & 0x00ff0000) >> 16; - - return *this; - } -}; - -class GlyphSet; -class PrinterJob; -class PrintFontManager; -struct CharacterMetric; - -/* - * Bitmap Interface, this has to be filled with your actual bitmap implementation - * sample implementations can be found in: - * psprint/workben/cui/pspdem.cxx - * vcl/unx/source/gdi/salgdi2.cxx - */ - -class PrinterBmp -{ -public: - - virtual ~PrinterBmp () = 0; - virtual sal_uInt32 GetPaletteColor (sal_uInt32 nIdx) const = 0; - virtual sal_uInt32 GetPaletteEntryCount () const = 0; - virtual sal_uInt32 GetPixelRGB (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0; - virtual sal_uInt8 GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0; - virtual sal_uInt8 GetPixelIdx (sal_uInt32 nRow, sal_uInt32 nColumn) const = 0; - virtual sal_uInt32 GetDepth () const = 0; -}; - -enum class ImageType { - TrueColorImage, - MonochromeImage, - PaletteImage, - GrayScaleImage -}; - -/* - * printer raster operations - */ - -struct GraphicsStatus -{ - OString maFont; - rtl_TextEncoding maEncoding; - bool mbArtItalic; - bool mbArtBold; - sal_Int32 mnTextHeight; - sal_Int32 mnTextWidth; - PrinterColor maColor; - double mfLineWidth; - - GraphicsStatus(); -}; - -class PrinterGfx -{ -private: - - /* common settings */ - - double mfScaleX; - double mfScaleY; - - sal_uInt32 mnDpi; - sal_uInt16 mnDepth; - - sal_uInt16 mnPSLevel; - bool mbColor; - bool mbUploadPS42Fonts; - - osl::File* mpPageBody; - - /* text/font related data, for a type1 font it has to be checked - whether this font has already been downloaded. A TrueType font - will be converted into one or more Type3 fonts, containing glyphs - in no particular order. In addition to the existence of the - glyph in one of the subfonts, the mapping from unicode to the - glyph has to be remembered */ - - std::vector< GlyphSet > maPS3Font; - - sal_Int32 mnFontID; - Degree10 mnTextAngle; - bool mbTextVertical; - PrintFontManager& mrFontMgr; - - /* bitmap drawing implementation */ - - void DrawPS1GrayImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea); - void writePS2ImageHeader (const tools::Rectangle& rArea, psp::ImageType nType); - void writePS2Colorspace (const PrinterBmp& rBitmap, psp::ImageType nType); - void DrawPS2GrayImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea); - void DrawPS2PaletteImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea); - void DrawPS2TrueColorImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea); - void DrawPS2MonoImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea); - - /* clip region */ - - std::list< tools::Rectangle > maClipRegion; - bool JoinVerticalClipRectangles( std::list< tools::Rectangle >::iterator& it, - Point& aOldPoint, sal_Int32& nColumn ); - - /* color settings */ - PrinterColor maFillColor; - PrinterColor maTextColor; - PrinterColor maLineColor; - - /* graphics state */ - GraphicsStatus maVirtualStatus; - std::list< GraphicsStatus > maGraphicsStack; - GraphicsStatus& currentState() { return maGraphicsStack.front(); } - -public: - /* graphics status update */ - void PSSetColor (); - void PSSetLineWidth (); - void PSSetFont (); - - /* graphics status functions */ - void PSSetColor (const PrinterColor& rColor) - { maVirtualStatus.maColor = rColor; } - - void PSSetFont (const OString& rName, - rtl_TextEncoding nEncoding) - { maVirtualStatus.maFont = rName; maVirtualStatus.maEncoding = nEncoding; } - - /* graphics status stack */ - void PSGSave (); - void PSGRestore (); - - /* PS helpers */ - enum pspath_t { moveto = 0, lineto = 1 }; - void PSBinLineTo (const Point& rCurrent, Point& rOld, - sal_Int32& nColumn); - void PSBinMoveTo (const Point& rCurrent, Point& rOld, - sal_Int32& nColumn); - void PSBinStartPath (); - void PSBinEndPath (); - void PSBinCurrentPath (sal_uInt32 nPoints, const Point* pPath); - void PSBinPath (const Point& rCurrent, Point& rOld, - pspath_t eType, sal_Int32& nColumn); - - void PSRotate (Degree10 nAngle); - void PSTranslate (const Point& rPoint); - void PSMoveTo (const Point& rPoint); - void PSScale (double fScaleX, double fScaleY); - void PSLineTo(const Point& rPoint ); - void PSPointOp (const Point& rPoint, const char* pOperator); - void PSHexString (const unsigned char* pString, sal_Int16 nLen); - void PSShowGlyph (const unsigned char nGlyphId); - - void OnEndJob (); - void writeResources( osl::File* pFile, std::vector< OString >& rSuppliedFonts ); - PrintFontManager& GetFontMgr () { return mrFontMgr; } - - void drawGlyph(const Point& rPoint, - sal_GlyphId aGlyphId); -public: - PrinterGfx(); - ~PrinterGfx(); - void Init (PrinterJob &rPrinterSpec); - void Init (const JobData& rData); - void Clear(); - - // query depth - sal_uInt16 GetBitCount () const { return mnDepth;} - - // clip region - void ResetClipRegion (); - void BeginSetClipRegion(); - void UnionClipRegion (sal_Int32 nX, sal_Int32 nY, - sal_Int32 nDX, sal_Int32 nDY); - void EndSetClipRegion (); - - // set xy color - void SetLineColor (const PrinterColor& rLineColor = PrinterColor()) - { maLineColor = rLineColor; } - void SetFillColor (const PrinterColor& rFillColor = PrinterColor()) - { maFillColor = rFillColor; } - - // drawing primitives - void DrawPixel (const Point& rPoint, const PrinterColor& rPixelColor); - void DrawPixel (const Point& rPoint) - { DrawPixel (rPoint, maLineColor); } - void DrawLine (const Point& rFrom, const Point& rTo); - void DrawRect (const tools::Rectangle& rRectangle); - void DrawPolyLine (sal_uInt32 nPoints, const Point* pPath ); - void DrawPolygon (sal_uInt32 nPoints, const Point* pPath); - void DrawPolyPolygon (sal_uInt32 nPoly, - const sal_uInt32 *pPolygonSize, - const Point** pPolygonList); - void DrawPolyLineBezier (sal_uInt32 nPoints, - const Point* pPath, - const PolyFlags* pFlgAry ); - void DrawPolygonBezier (sal_uInt32 nPoints, - const Point* pPath, - const PolyFlags* pFlgAry); - void DrawPolyPolygonBezier (sal_uInt32 nPoly, - const sal_uInt32* pPoints, - const Point* const* pPtAry, - const PolyFlags* const* pFlgAry); - - // eps - bool DrawEPS ( const tools::Rectangle& rBoundingBox, void* pPtr, sal_uInt32 nSize); - - // image drawing - void DrawBitmap (const tools::Rectangle& rDest, const tools::Rectangle& rSrc, - const PrinterBmp& rBitmap); - - // font and text handling - void SetFont ( - sal_Int32 nFontID, - sal_Int32 nPointHeight, - sal_Int32 nPointWidth, - Degree10 nAngle, - bool bVertical, - bool bArtItalic, - bool bArtBold - ); - sal_Int32 GetFontID () const - { return mnFontID; } - bool GetFontVertical() const - { return mbTextVertical; } - sal_Int32 GetFontHeight () const - { return maVirtualStatus.mnTextHeight; } - sal_Int32 GetFontWidth () const - { return maVirtualStatus.mnTextWidth; } - bool GetArtificialItalic() const - { return maVirtualStatus.mbArtItalic; } - bool GetArtificialBold() const - { return maVirtualStatus.mbArtBold; } - void SetTextColor (PrinterColor const & rTextColor) - { maTextColor = rTextColor; } - - void DrawGlyph(const Point& rPoint, - const GlyphItem& rGlyph); - -}; - -} /* namespace psp */ - -#endif // INCLUDED_VCL_INC_GENERIC_PRINTERGFX_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/unx/printerjob.hxx b/vcl/inc/unx/printerjob.hxx deleted file mode 100644 index 47d1c0ac9c96..000000000000 --- a/vcl/inc/unx/printerjob.hxx +++ /dev/null @@ -1,129 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_VCL_INC_GENERIC_PRINTERJOB_HXX -#define INCLUDED_VCL_INC_GENERIC_PRINTERJOB_HXX - -#include <jobdata.hxx> -#include <osl/file.hxx> - -#include <string_view> -#include <vector> - -namespace psp { - -class PrinterGfx; - -class PrinterJob -{ -private: - OUString maSpoolDirName; - OUString maFileName; // empty: spool to command, else spool to named file - OUString maJobTitle; - int mnFileMode; - - std::unique_ptr<osl::File> mpJobHeader; - std::unique_ptr<osl::File> mpJobTrailer; - - std::vector< std::unique_ptr<osl::File> > maPageVector; - std::vector< std::unique_ptr<osl::File> > maHeaderVector; - - JobData m_aDocumentJobData; - JobData m_aLastJobData; - PrinterGfx* m_pGraphics; - - sal_uInt32 mnResolution; - - sal_uInt32 mnWidthPt; - sal_uInt32 mnHeightPt; - sal_uInt32 mnMaxWidthPt; - sal_uInt32 mnMaxHeightPt; - - int mnLandscapes; - int mnPortraits; - - sal_uInt32 mnLMarginPt; - sal_uInt32 mnRMarginPt; - sal_uInt32 mnTMarginPt; - sal_uInt32 mnBMarginPt; - - double mfXScale; - double mfYScale; - - bool m_bQuickJob; - -private: - std::unique_ptr<osl::File> CreateSpoolFile (std::u16string_view rName, - std::u16string_view rExtension) const; - void InitPaperSize (const JobData& rJobSetup); - - bool writeFeatureList( osl::File* pFile, const JobData&, bool bDocumentSetup ) const; - bool writeSetup( osl::File* pFile, const JobData& ); - bool writePageSetup( osl::File* pFile, const JobData&, bool bWriteFeatures ); - static void writeJobPatch( osl::File* File, const JobData& ); - static void writeProlog (osl::File* pFile, const JobData& ); - -public: // for usage in PrinterGfx - sal_uInt32 GetResolution () const { return mnResolution; } - void GetScale (double &rXScale, double &rYScale) const; - sal_uInt16 GetDepth () const; - sal_uInt16 GetPostscriptLevel (const JobData *pJobData = nullptr) const; - bool IsColorPrinter () const; - - osl::File* GetCurrentPageBody (); - - const OUString& GetPrinterName() const { return m_aLastJobData.m_aPrinterName; } - -public: - PrinterJob (); - ~PrinterJob (); - - /* rFileName: if length is greater than 0 save resulting PostScript - * to named file. - * nMode: only meaningful when saving to file: if nonzero, try - * to impose the mode on the resulting file's inode; for nonexistent - * files use open, for existent files try a chmod - * rJobName: text to appear in the %%Title comment - * rAppName: text to appear in the %%Creator comment - * rSetupData: JobData that apply to this job - * pGraphics: the graphics used to print this job; - * this graphics must live until EndJob() has returned - * bIsQuickJob: the job was started as "direct print" meaning - * the quick command for spooling should be used instead - * of the normal command - */ - bool StartJob (const OUString& rFileName, - int nMode, - const OUString& rJobName, - std::u16string_view rAppName, - const JobData& rSetupData, - PrinterGfx* pGraphics, - bool bIsQuickJob - ); - bool EndJob (); - - void StartPage (const JobData& rJobSetup); - void EndPage (); -}; - -} // namespace psp - -#endif // INCLUDED_VCL_INC_GENERIC_PRINTERJOB_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/print/bitmap_gfx.cxx b/vcl/unx/generic/print/bitmap_gfx.cxx deleted file mode 100644 index 2d8649706060..000000000000 --- a/vcl/unx/generic/print/bitmap_gfx.cxx +++ /dev/null @@ -1,674 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <array> -#include <memory> -#include "psputil.hxx" - -#include <unx/printergfx.hxx> - -namespace psp { - -const sal_uInt32 nLineLength = 80; -const sal_uInt32 nBufferSize = 16384; - -/* - * - * Bitmap compression / Hex encoding / Ascii85 Encoding - * - */ - -PrinterBmp::~PrinterBmp() -{ -} - -/* HexEncoder */ - -namespace { - -class HexEncoder -{ -private: - - osl::File* mpFile; - sal_uInt32 mnColumn; - sal_uInt32 mnOffset; - OStringBuffer mpFileBuffer; - -public: - - explicit HexEncoder (osl::File* pFile); - ~HexEncoder (); - void WriteAscii (sal_uInt8 nByte); - void EncodeByte (sal_uInt8 nByte); - void FlushLine (); -}; - -} - -HexEncoder::HexEncoder (osl::File* pFile) : - mpFile (pFile), - mnColumn (0), - mnOffset (0) -{} - -HexEncoder::~HexEncoder () -{ - FlushLine (); - if (mnColumn > 0) - WritePS (mpFile, "\n"); -} - -void -HexEncoder::WriteAscii (sal_uInt8 nByte) -{ - sal_uInt32 nOff = psp::getHexValueOf (nByte, mpFileBuffer); - mnColumn += nOff; - mnOffset += nOff; - - if (mnColumn >= nLineLength) - { - mnOffset += psp::appendStr ("\n", mpFileBuffer); - mnColumn = 0; - } - if (mnOffset >= nBufferSize) - FlushLine (); -} - -void -HexEncoder::EncodeByte (sal_uInt8 nByte) -{ - WriteAscii (nByte); -} - -void -HexEncoder::FlushLine () -{ - if (mnOffset > 0) - { - WritePS (mpFile, mpFileBuffer.makeStringAndClear()); - mnOffset = 0; - } -} - -/* Ascii85 encoder, is abi compatible with HexEncoder but writes a ~> to - indicate end of data EOD */ - -namespace { - -class Ascii85Encoder -{ -private: - - osl::File* mpFile; - sal_uInt32 mnByte; - sal_uInt8 mpByteBuffer[4]; - - sal_uInt32 mnColumn; - sal_uInt32 mnOffset; - OStringBuffer mpFileBuffer; - - inline void PutByte (sal_uInt8 nByte); - inline void PutEOD (); - void ConvertToAscii85 (); - void FlushLine (); - -public: - - explicit Ascii85Encoder (osl::File* pFile); - virtual ~Ascii85Encoder (); - virtual void EncodeByte (sal_uInt8 nByte); - void WriteAscii (sal_uInt8 nByte); -}; - -} - -Ascii85Encoder::Ascii85Encoder (osl::File* pFile) : - mpFile (pFile), - mnByte (0), - mnColumn (0), - mnOffset (0) -{} - -inline void -Ascii85Encoder::PutByte (sal_uInt8 nByte) -{ - mpByteBuffer [mnByte++] = nByte; -} - -inline void -Ascii85Encoder::PutEOD () -{ - WritePS (mpFile, "~>\n"); -} - -void -Ascii85Encoder::ConvertToAscii85 () -{ - // Add (4 - mnByte) zero padding bytes: - if (mnByte < 4) - std::memset (mpByteBuffer + mnByte, 0, (4 - mnByte) * sizeof(sal_uInt8)); - - sal_uInt32 nByteValue = mpByteBuffer[0] * 256 * 256 * 256 - + mpByteBuffer[1] * 256 * 256 - + mpByteBuffer[2] * 256 - + mpByteBuffer[3]; - - if (nByteValue == 0 && mnByte == 4) - { - /* special case of 4 Bytes in row */ - mpFileBuffer.append('z'); - - mnOffset += 1; - mnColumn += 1; - } - else - { - /* real ascii85 encoding */ - - // Of the up to 5 characters to be generated, do not generate the last (4 - mnByte) ones - // that correspond to the (4 - mnByte) zero padding bytes added to the input: - - auto const pos = mpFileBuffer.getLength(); - if (mnByte == 4) { - mpFileBuffer.insert(pos, char((nByteValue % 85) + 33)); - } - nByteValue /= 85; - if (mnByte >= 3) { - mpFileBuffer.insert(pos, char((nByteValue % 85) + 33)); - } - nByteValue /= 85; - if (mnByte >= 2) { - mpFileBuffer.insert(pos, char((nByteValue % 85) + 33)); - } - nByteValue /= 85; - mpFileBuffer.insert(pos, char((nByteValue % 85) + 33)); - nByteValue /= 85; - mpFileBuffer.insert(pos, char((nByteValue % 85) + 33)); - - mnColumn += (mnByte + 1); - mnOffset += (mnByte + 1); - - /* insert a newline if necessary */ - if (mnColumn > nLineLength) - { - sal_uInt32 nEolOff = mnColumn - nLineLength; - auto const posNl = pos + (mnByte + 1) - nEolOff; - - mpFileBuffer.insert(posNl, '\n'); - - mnOffset++; - mnColumn = nEolOff; - } - } - - mnByte = 0; -} - -void -Ascii85Encoder::WriteAscii (sal_uInt8 nByte) -{ - PutByte (nByte); - if (mnByte == 4) - ConvertToAscii85 (); - - if (mnColumn >= nLineLength) - { - mnOffset += psp::appendStr ("\n", mpFileBuffer); - mnColumn = 0; - } - if (mnOffset >= nBufferSize) - FlushLine (); -} - -void -Ascii85Encoder::EncodeByte (sal_uInt8 nByte) -{ - WriteAscii (nByte); -} - -void -Ascii85Encoder::FlushLine () -{ - if (mnOffset > 0) - { - WritePS (mpFile, mpFileBuffer.makeStringAndClear()); - mnOffset = 0; - } -} - -Ascii85Encoder::~Ascii85Encoder () -{ - if (mnByte > 0) - ConvertToAscii85 (); - if (mnOffset > 0) - FlushLine (); - PutEOD (); -} - -/* LZW encoder */ - -namespace { - -class LZWEncoder : public Ascii85Encoder -{ -private: - - struct LZWCTreeNode - { - LZWCTreeNode* mpBrother; // next node with same parent - LZWCTreeNode* mpFirstChild; // first son - sal_uInt16 mnCode; // code for the string - sal_uInt16 mnValue; // pixelvalue - }; - - std::array<LZWCTreeNode, 4096> - maTable; // LZW compression data - LZWCTreeNode* mpPrefix; // the compression is as same as the TIFF compression - static constexpr sal_uInt16 gnDataSize = 8; - static constexpr sal_uInt16 gnClearCode = 1 << gnDataSize; - static constexpr sal_uInt16 gnEOICode = gnClearCode + 1; - sal_uInt16 mnTableSize; - sal_uInt16 mnCodeSize; - sal_uInt32 mnOffset; - sal_uInt32 mdwShift; - - void WriteBits (sal_uInt16 nCode, sal_uInt16 nCodeLen); - -public: - - explicit LZWEncoder (osl::File* pOutputFile); - virtual ~LZWEncoder () override; - - virtual void EncodeByte (sal_uInt8 nByte) override; -}; - -} - -LZWEncoder::LZWEncoder(osl::File* pOutputFile) : - Ascii85Encoder (pOutputFile), - maTable{{}}, - mpPrefix(nullptr), - mnTableSize(gnEOICode + 1), - mnCodeSize(gnDataSize + 1), - mnOffset(32), // free bits in dwShift - mdwShift(0) -{ - for (sal_uInt32 i = 0; i < 4096; i++) - { - maTable[i].mpBrother = nullptr; - maTable[i].mpFirstChild = nullptr; - maTable[i].mnCode = i; - maTable[i].mnValue = static_cast<sal_uInt8>(maTable[i].mnCode); - } - - WriteBits( gnClearCode, mnCodeSize ); -} - -LZWEncoder::~LZWEncoder() -{ - if (mpPrefix) - WriteBits (mpPrefix->mnCode, mnCodeSize); - - WriteBits (gnEOICode, mnCodeSize); -} - -void -LZWEncoder::WriteBits (sal_uInt16 nCode, sal_uInt16 nCodeLen) -{ - mdwShift |= (nCode << (mnOffset - nCodeLen)); - mnOffset -= nCodeLen; - while (mnOffset < 24) - { - WriteAscii (static_cast<sal_uInt8>(mdwShift >> 24)); - mdwShift <<= 8; - mnOffset += 8; - } - if (nCode == 257 && mnOffset != 32) - WriteAscii (static_cast<sal_uInt8>(mdwShift >> 24)); -} - -void -LZWEncoder::EncodeByte (sal_uInt8 nByte ) -{ - LZWCTreeNode* p; - sal_uInt16 i; - sal_uInt8 nV; - - if (!mpPrefix) - { - mpPrefix = maTable.data() + nByte; - } - else - { - nV = nByte; - for (p = mpPrefix->mpFirstChild; p != nullptr; p = p->mpBrother) - { - if (p->mnValue == nV) - break; - } - - if (p != nullptr) - { - mpPrefix = p; - } - else - { - WriteBits (mpPrefix->mnCode, mnCodeSize); - - if (mnTableSize == 409) - { - WriteBits (gnClearCode, mnCodeSize); - - for (i = 0; i < gnClearCode; i++) - maTable[i].mpFirstChild = nullptr; - - mnCodeSize = gnDataSize + 1; - mnTableSize = gnEOICode + 1; - } - else - { - if(mnTableSize == static_cast<sal_uInt16>((1 << mnCodeSize) - 1)) - mnCodeSize++; - - p = maTable.data() + (mnTableSize++); - p->mpBrother = mpPrefix->mpFirstChild; - mpPrefix->mpFirstChild = p; - p->mnValue = nV; - p->mpFirstChild = nullptr; - } - - mpPrefix = maTable.data() + nV; - } - } -} - -/* - * - * bitmap handling routines - * - */ - -void -PrinterGfx::DrawBitmap (const tools::Rectangle& rDest, const tools::Rectangle& rSrc, - const PrinterBmp& rBitmap) -{ - double fScaleX = static_cast<double>(rDest.GetWidth()); - double fScaleY = static_cast<double>(rDest.GetHeight()); - if(rSrc.GetWidth() > 0) - { - fScaleX = static_cast<double>(rDest.GetWidth()) / static_cast<double>(rSrc.GetWidth()); - } - if(rSrc.GetHeight() > 0) - { - fScaleY = static_cast<double>(rDest.GetHeight()) / static_cast<double>(rSrc.GetHeight()); - } - PSGSave (); - PSTranslate (rDest.BottomLeft()); - PSScale (fScaleX, fScaleY); - - if (mnPSLevel >= 2) - { - if (rBitmap.GetDepth() == 1) - { - DrawPS2MonoImage (rBitmap, rSrc); - } - else - if (rBitmap.GetDepth() == 8 && mbColor) - { - // if the palette is larger than the image itself print it as a truecolor - // image to save diskspace. This is important for printing transparent - // bitmaps that are disassembled into small pieces - sal_Int32 nImageSz = rSrc.GetWidth() * rSrc.GetHeight(); - sal_Int32 nPaletteSz = rBitmap.GetPaletteEntryCount(); - if ((nImageSz < nPaletteSz) || (nImageSz < 24) ) - DrawPS2TrueColorImage (rBitmap, rSrc); - else - DrawPS2PaletteImage (rBitmap, rSrc); - } - else - if (rBitmap.GetDepth() == 24 && mbColor) - { - DrawPS2TrueColorImage (rBitmap, rSrc); - } - else - { - DrawPS2GrayImage (rBitmap, rSrc); - } - } - else - { - DrawPS1GrayImage (rBitmap, rSrc); - } - - PSGRestore (); -} - -/* - * - * Implementation: PS Level 1 - * - */ - -void -PrinterGfx::DrawPS1GrayImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea) -{ - sal_uInt32 nWidth = rArea.GetWidth(); - sal_uInt32 nHeight = rArea.GetHeight(); - - OStringBuffer pGrayImage; - - // image header - psp::getValueOf (nWidth, pGrayImage); - psp::appendStr (" ", pGrayImage); - psp::getValueOf (nHeight, pGrayImage); - psp::appendStr (" 8 ", pGrayImage); - psp::appendStr ("[ 1 0 0 1 0 ", pGrayImage); - psp::getValueOf (nHeight, pGrayImage); - psp::appendStr ("]", pGrayImage); - psp::appendStr (" {currentfile ", pGrayImage); - psp::getValueOf (nWidth, pGrayImage); - psp::appendStr (" string readhexstring pop}\n", pGrayImage); - psp::appendStr ("image\n", pGrayImage); - - WritePS (mpPageBody, pGrayImage.makeStringAndClear()); - - // image body - HexEncoder aEncoder(mpPageBody); - - for (tools::Long nRow = rArea.Top(); nRow <= rArea.Bottom(); nRow++) - { - for (tools::Long nColumn = rArea.Left(); nColumn <= rArea.Right(); nColumn++) - { - unsigned char nByte = rBitmap.GetPixelGray (nRow, nColumn); - aEncoder.EncodeByte (nByte); - } - } - - WritePS (mpPageBody, "\n"); -} - -/* - * - * Implementation: PS Level 2 - * - */ - -void -PrinterGfx::writePS2ImageHeader (const tools::Rectangle& rArea, psp::ImageType nType) -{ - OStringBuffer pImage; - - sal_Int32 nDictType = 0; - switch (nType) - { - case psp::ImageType::TrueColorImage: nDictType = 0; break; - case psp::ImageType::PaletteImage: nDictType = 1; break; - case psp::ImageType::GrayScaleImage: nDictType = 2; break; - case psp::ImageType::MonochromeImage: nDictType = 3; break; - default: break; - } - - psp::getValueOf (rArea.GetWidth(), pImage); - psp::appendStr (" ", pImage); - psp::getValueOf (rArea.GetHeight(), pImage); - psp::appendStr (" ", pImage); - psp::getValueOf (nDictType, pImage); - psp::appendStr (" ", pImage); - psp::getValueOf (sal_Int32(1), pImage); // nCompressType - psp::appendStr (" psp_imagedict image\n", pImage); - - WritePS (mpPageBody, pImage.makeStringAndClear()); -} - -void -PrinterGfx::writePS2Colorspace(const PrinterBmp& rBitmap, psp::ImageType nType) -{ - switch (nType) - { - case psp::ImageType::GrayScaleImage: - - WritePS (mpPageBody, "/DeviceGray setcolorspace\n"); - break; - - case psp::ImageType::TrueColorImage: - - WritePS (mpPageBody, "/DeviceRGB setcolorspace\n"); - break; - - case psp::ImageType::MonochromeImage: - case psp::ImageType::PaletteImage: - { - - OStringBuffer pImage; - - const sal_uInt32 nSize = rBitmap.GetPaletteEntryCount(); - - psp::appendStr ("[/Indexed /DeviceRGB ", pImage); - psp::getValueOf (nSize - 1, pImage); - psp::appendStr ("\npsp_lzwstring\n", pImage); - WritePS (mpPageBody, pImage.makeStringAndClear()); - - LZWEncoder aEncoder(mpPageBody); - for (sal_uInt32 i = 0; i < nSize; i++) - { - PrinterColor aColor = rBitmap.GetPaletteColor(i); - - aEncoder.EncodeByte (aColor.GetRed()); - aEncoder.EncodeByte (aColor.GetGreen()); - aEncoder.EncodeByte (aColor.GetBlue()); - } - - WritePS (mpPageBody, "pop ] setcolorspace\n"); - } - break; - default: break; - } -} - -void -PrinterGfx::DrawPS2GrayImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea) -{ - writePS2Colorspace(rBitmap, psp::ImageType::GrayScaleImage); - writePS2ImageHeader(rArea, psp::ImageType::GrayScaleImage); - - LZWEncoder aEncoder(mpPageBody); - - for (tools::Long nRow = rArea.Top(); nRow <= rArea.Bottom(); nRow++) - { - for (tools::Long nColumn = rArea.Left(); nColumn <= rArea.Right(); nColumn++) - { - unsigned char nByte = rBitmap.GetPixelGray (nRow, nColumn); - aEncoder.EncodeByte (nByte); - } - } -} - -void -PrinterGfx::DrawPS2MonoImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea) -{ - writePS2Colorspace(rBitmap, psp::ImageType::MonochromeImage); - writePS2ImageHeader(rArea, psp::ImageType::MonochromeImage); - - LZWEncoder aEncoder(mpPageBody); - - for (tools::Long nRow = rArea.Top(); nRow <= rArea.Bottom(); nRow++) - { - tools::Long nBitPos = 0; - unsigned char nByte = 0; - - for (tools::Long nColumn = rArea.Left(); nColumn <= rArea.Right(); nColumn++) - { - unsigned char nBit = rBitmap.GetPixelIdx (nRow, nColumn); - nByte |= nBit << (7 - nBitPos); - - if (++nBitPos == 8) - { - aEncoder.EncodeByte (nByte); - nBitPos = 0; - nByte = 0; - } - } - // keep the row byte aligned - if (nBitPos != 0) - aEncoder.EncodeByte (nByte); - } -} - -void -PrinterGfx::DrawPS2PaletteImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea) -{ - writePS2Colorspace(rBitmap, psp::ImageType::PaletteImage); - writePS2ImageHeader(rArea, psp::ImageType::PaletteImage); - - LZWEncoder aEncoder(mpPageBody); - - for (tools::Long nRow = rArea.Top(); nRow <= rArea.Bottom(); nRow++) - { - for (tools::Long nColumn = rArea.Left(); nColumn <= rArea.Right(); nColumn++) - { - unsigned char nByte = rBitmap.GetPixelIdx (nRow, nColumn); - aEncoder.EncodeByte (nByte); - } - } -} - -void -PrinterGfx::DrawPS2TrueColorImage (const PrinterBmp& rBitmap, const tools::Rectangle& rArea) -{ - writePS2Colorspace(rBitmap, psp::ImageType::TrueColorImage); - writePS2ImageHeader(rArea, psp::ImageType::TrueColorImage); - - LZWEncoder aEncoder(mpPageBody); - - for (tools::Long nRow = rArea.Top(); nRow <= rArea.Bottom(); nRow++) - { - for (tools::Long nColumn = rArea.Left(); nColumn <= rArea.Right(); nColumn++) - { - PrinterColor aColor = rBitmap.GetPixelRGB (nRow, nColumn); - aEncoder.EncodeByte (aColor.GetRed()); - aEncoder.EncodeByte (aColor.GetGreen()); - aEncoder.EncodeByte (aColor.GetBlue()); - } - } -} - -} /* namespace psp */ - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/print/common_gfx.cxx b/vcl/unx/generic/print/common_gfx.cxx deleted file mode 100644 index aba50ece2693..000000000000 --- a/vcl/unx/generic/print/common_gfx.cxx +++ /dev/null @@ -1,1152 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <sal/config.h> - -#include "psputil.hxx" -#include "glyphset.hxx" - -#include <unx/printergfx.hxx> -#include <unx/printerjob.hxx> -#include <unx/fontmanager.hxx> -#include <strhelper.hxx> -#include <printerinfomanager.hxx> - -#include <tools/color.hxx> -#include <tools/poly.hxx> -#include <tools/stream.hxx> -#include <o3tl/string_view.hxx> - -using namespace psp ; - -const sal_Int32 nMaxTextColumn = 80; - -GraphicsStatus::GraphicsStatus() : - maEncoding(RTL_TEXTENCODING_DONTKNOW), - mbArtItalic( false ), - mbArtBold( false ), - mnTextHeight( 0 ), - mnTextWidth( 0 ), - mfLineWidth( -1 ) -{ -} - -/* - * non graphics routines - */ - -void -PrinterGfx::Init (PrinterJob &rPrinterJob) -{ - mpPageBody = rPrinterJob.GetCurrentPageBody (); - mnDepth = rPrinterJob.GetDepth (); - mnPSLevel = rPrinterJob.GetPostscriptLevel (); - mbColor = rPrinterJob.IsColorPrinter (); - - mnDpi = rPrinterJob.GetResolution(); - rPrinterJob.GetScale (mfScaleX, mfScaleY); - const PrinterInfo& rInfo( PrinterInfoManager::get().getPrinterInfo( rPrinterJob.GetPrinterName() ) ); - mbUploadPS42Fonts = rInfo.m_pParser && rInfo.m_pParser->isType42Capable(); -} - -void -PrinterGfx::Init (const JobData& rData) -{ - mpPageBody = nullptr; - mnDepth = rData.m_nColorDepth; - mnPSLevel = rData.m_nPSLevel ? rData.m_nPSLevel : (rData.m_pParser ? rData.m_pParser->getLanguageLevel() : 2 ); - mbColor = rData.m_nColorDevice ? ( rData.m_nColorDevice != -1 ) : ( rData.m_pParser == nullptr || rData.m_pParser->isColorDevice() ); - int nRes = rData.m_aContext.getRenderResolution(); - mnDpi = nRes; - mfScaleX = 72.0 / static_cast<double>(mnDpi); - mfScaleY = 72.0 / static_cast<double>(mnDpi); - const PrinterInfo& rInfo( PrinterInfoManager::get().getPrinterInfo( rData.m_aPrinterName ) ); - mbUploadPS42Fonts = rInfo.m_pParser && rInfo.m_pParser->isType42Capable(); -} - - -PrinterGfx::PrinterGfx() - : mfScaleX(0.0) - , mfScaleY(0.0) - , mnDpi(0) - , mnDepth(0) - , mnPSLevel(0) - , mbColor(false) - , mbUploadPS42Fonts(false) - , mpPageBody(nullptr) - , mnFontID(0) - , mnTextAngle(0) - , mbTextVertical(false) - , mrFontMgr(PrintFontManager::get()) - , maFillColor(0xff,0,0) - , maTextColor(0,0,0) - , maLineColor(0, 0xff, 0) -{ - maVirtualStatus.mfLineWidth = 1.0; - maVirtualStatus.mnTextHeight = 12; - maVirtualStatus.mnTextWidth = 0; - - maGraphicsStack.emplace_back( ); -} - -PrinterGfx::~PrinterGfx() -{ -} - -void -PrinterGfx::Clear() -{ - mpPageBody = nullptr; - mnFontID = 0; - maVirtualStatus = GraphicsStatus(); - maVirtualStatus.mnTextHeight = 12; - maVirtualStatus.mnTextWidth = 0; - maVirtualStatus.mfLineWidth = 1.0; - mbTextVertical = false; - maLineColor = PrinterColor(); - maFillColor = PrinterColor(); - maTextColor = PrinterColor(); - mnDpi = 300; - mnDepth = 24; - mnPSLevel = 2; - mbColor = true; - mnTextAngle = 0_deg10; - - maClipRegion.clear(); - maGraphicsStack.clear(); - maGraphicsStack.emplace_back( ); -} - -/* - * clip region handling - */ - -void -PrinterGfx::ResetClipRegion() -{ - maClipRegion.clear(); - PSGRestore (); - PSGSave (); // get "clean" clippath -} - -void -PrinterGfx::BeginSetClipRegion() -{ - maClipRegion.clear(); -} - -void -PrinterGfx::UnionClipRegion (sal_Int32 nX,sal_Int32 nY,sal_Int32 nDX,sal_Int32 nDY) -{ - if( nDX && nDY ) - maClipRegion.emplace_back(Point(nX,nY ), Size(nDX,nDY)); -} - -bool -PrinterGfx::JoinVerticalClipRectangles( std::list< tools::Rectangle >::iterator& it, - Point& rOldPoint, sal_Int32& rColumn ) -{ - bool bSuccess = false; - - std::list< tools::Rectangle >::iterator tempit, nextit; - nextit = it; - ++nextit; - std::list< Point > leftside, rightside; - - tools::Rectangle aLastRect( *it ); - leftside.emplace_back( it->Left(), it->Top() ); - rightside.emplace_back( it->Right()+1, it->Top() ); - while( nextit != maClipRegion.end() ) - { - tempit = nextit; - ++tempit; - if( nextit->Top() == aLastRect.Bottom()+1 ) - { - if( - ( nextit->Left() >= aLastRect.Left() && nextit->Left() <= aLastRect.Right() ) // left endpoint touches last rectangle - || - ( nextit->Right() >= aLastRect.Left() && nextit->Right() <= aLastRect.Right() ) // right endpoint touches last rectangle - || - ( nextit->Left() <= aLastRect.Left() && nextit->Right() >= aLastRect.Right() ) // whole line touches last rectangle - ) - { - if( aLastRect.GetHeight() > 1 || - std::abs( aLastRect.Left() - nextit->Left() ) > 2 || - std::abs( aLastRect.Right() - nextit->Right() ) > 2 - ) - { - leftside.emplace_back( aLastRect.Left(), aLastRect.Bottom()+1 ); - rightside.emplace_back( aLastRect.Right()+1, aLastRect.Bottom()+1 ); - } - aLastRect = *nextit; - leftside.push_back( aLastRect.TopLeft() ); - rightside.push_back( aLastRect.TopRight() ); - maClipRegion.erase( nextit ); - } - } - nextit = tempit; - } - if( leftside.size() > 1 ) - { - // push the last coordinates - leftside.emplace_back( aLastRect.Left(), aLastRect.Bottom()+1 ); - rightside.emplace_back( aLastRect.Right()+1, aLastRect.Bottom()+1 ); - - // cool, we can concatenate rectangles - const int nDX = -65536, nDY = 65536; - int nNewDX = 0, nNewDY = 0; - - Point aLastPoint = leftside.front(); - PSBinMoveTo (aLastPoint, rOldPoint, rColumn); - leftside.pop_front(); - while( !leftside.empty() ) - { - Point aPoint (leftside.front()); - leftside.pop_front(); - // may have been the last one - if( !leftside.empty() ) - { - nNewDX = aPoint.X() - aLastPoint.X(); - nNewDY = aPoint.Y() - aLastPoint.Y(); - if( nNewDX != 0 && - static_cast<double>(nNewDY)/static_cast<double>(nNewDX) == double(nDY)/double(nDX) ) - continue; - } - PSBinLineTo (aPoint, rOldPoint, rColumn); - aLastPoint = aPoint; - } - - aLastPoint = rightside.back(); - PSBinLineTo (aLastPoint, rOldPoint, rColumn); - rightside.pop_back(); - while( !rightside.empty() ) - { - Point aPoint (rightside.back()); - rightside.pop_back(); - if( !rightside.empty() ) - { - nNewDX = aPoint.X() - aLastPoint.X(); - nNewDY = aPoint.Y() - aLastPoint.Y(); - if( nNewDX != 0 && - static_cast<double>(nNewDY)/static_cast<double>(nNewDX) == double(nDY)/double(nDX) ) - continue; - } - PSBinLineTo (aPoint, rOldPoint, rColumn); - } - - tempit = it; - ++tempit; - maClipRegion.erase( it ); - it = tempit; - bSuccess = true; - } - return bSuccess; -} - -void -PrinterGfx::EndSetClipRegion() -{ - PSGRestore (); - PSGSave (); // get "clean" clippath - - PSBinStartPath (); - Point aOldPoint (0, 0); - sal_Int32 nColumn = 0; - - std::list< tools::Rectangle >::iterator it = maClipRegion.begin(); - while( it != maClipRegion.end() ) - { - // try to concatenate adjacent rectangles - // first try in y direction, then in x direction - if( ! JoinVerticalClipRectangles( it, aOldPoint, nColumn ) ) - { - // failed, so it is a single rectangle - PSBinMoveTo (Point( it->Left()-1, it->Top()-1), aOldPoint, nColumn ); - PSBinLineTo (Point( it->Left()-1, it->Bottom()+1 ), aOldPoint, nColumn ); - PSBinLineTo (Point( it->Right()+1, it->Bottom()+1 ), aOldPoint, nColumn ); - PSBinLineTo (Point( it->Right()+1, it->Top()-1 ), aOldPoint, nColumn ); - ++it; - } - } - - PSBinEndPath (); - - WritePS (mpPageBody, "closepath clip newpath\n"); - maClipRegion.clear(); -} - -/* - * draw graphic primitives - */ - -void -PrinterGfx::DrawRect (const tools::Rectangle& rRectangle ) -{ - OStringBuffer pRect; - - psp::getValueOf (rRectangle.Left(), pRect); - psp::appendStr (" ", pRect); - psp::getValueOf (rRectangle.Top(), pRect); - psp::appendStr (" ", pRect); - psp::getValueOf (rRectangle.GetWidth(), pRect); - psp::appendStr (" ", pRect); - psp::getValueOf (rRectangle.GetHeight(), pRect); - psp::appendStr (" ", pRect); - auto const rect = pRect.makeStringAndClear(); - - if( maFillColor.Is() ) - { - PSSetColor (maFillColor); - PSSetColor (); - WritePS (mpPageBody, rect); - WritePS (mpPageBody, "rectfill\n"); - } - if( maLineColor.Is() ) - { - PSSetColor (maLineColor); - PSSetColor (); - PSSetLineWidth (); - WritePS (mpPageBody, rect); - WritePS (mpPageBody, "rectstroke\n"); - } -} - -void -PrinterGfx::DrawLine (const Point& rFrom, const Point& rTo) -{ - if( maLineColor.Is() ) - { - PSSetColor (maLineColor); - PSSetColor (); - PSSetLineWidth (); - - PSMoveTo (rFrom); - PSLineTo (rTo); - WritePS (mpPageBody, "stroke\n" ); - } -} - -void -PrinterGfx::DrawPixel (const Point& rPoint, const PrinterColor& rPixelColor) -{ - if( rPixelColor.Is() ) - { - PSSetColor (rPixelColor); - PSSetColor (); - - PSMoveTo (rPoint); - PSLineTo (Point (rPoint.X ()+1, rPoint.Y ())); - PSLineTo (Point (rPoint.X ()+1, rPoint.Y ()+1)); - PSLineTo (Point (rPoint.X (), rPoint.Y ()+1)); - WritePS (mpPageBody, "fill\n" ); - } -} - -void -PrinterGfx::DrawPolyLine (sal_uInt32 nPoints, const Point* pPath) -{ - if( maLineColor.Is() && nPoints && pPath ) - { - PSSetColor (maLineColor); - PSSetColor (); - PSSetLineWidth (); - - PSBinCurrentPath (nPoints, pPath); - - WritePS (mpPageBody, "stroke\n" ); - } -} - -void -PrinterGfx::DrawPolygon (sal_uInt32 nPoints, const Point* pPath) -{ - // premature end of operation - if (nPoints <= 0 || (pPath == nullptr) || !(maFillColor.Is() || maLineColor.Is())) - return; - - // setup closed path - Point aPoint( 0, 0 ); - sal_Int32 nColumn( 0 ); - - PSBinStartPath(); - PSBinMoveTo( pPath[0], aPoint, nColumn ); - for( unsigned int n = 1; n < nPoints; n++ ) - PSBinLineTo( pPath[n], aPoint, nColumn ); - if( pPath[0] != pPath[nPoints-1] ) - PSBinLineTo( pPath[0], aPoint, nColumn ); - PSBinEndPath(); - - // fill the polygon first, then draw the border, note that fill and - // stroke reset the currentpath - - // if fill and stroke, save the current path - if( maFillColor.Is() && maLineColor.Is()) - PSGSave(); - - if (maFillColor.Is ()) - { - PSSetColor (maFillColor); - PSSetColor (); - WritePS (mpPageBody, "eofill\n"); - } - - // restore the current path - if( maFillColor.Is() && maLineColor.Is()) - PSGRestore(); - - if (maLineColor.Is ()) - { - PSSetColor (maLineColor); - PSSetColor (); - PSSetLineWidth (); - WritePS (mpPageBody, "stroke\n"); - } -} - -void -PrinterGfx::DrawPolyPolygon (sal_uInt32 nPoly, const sal_uInt32* pSizes, const Point** pPaths ) -{ - // sanity check - if ( !nPoly || !pPaths || !(maFillColor.Is() || maLineColor.Is())) - return; - - // setup closed path - for( unsigned int i = 0; i < nPoly; i++ ) - { - Point aPoint( 0, 0 ); - sal_Int32 nColumn( 0 ); - - PSBinStartPath(); - PSBinMoveTo( pPaths[i][0], aPoint, nColumn ); - for( unsigned int n = 1; n < pSizes[i]; n++ ) - PSBinLineTo( pPaths[i][n], aPoint, nColumn ); - if( pPaths[i][0] != pPaths[i][pSizes[i]-1] ) - PSBinLineTo( pPaths[i][0], aPoint, nColumn ); - PSBinEndPath(); - } - - // if eofill and stroke, save the current path - if( maFillColor.Is() && maLineColor.Is()) - PSGSave(); - - // first draw area - if( maFillColor.Is() ) - { - PSSetColor (maFillColor); - PSSetColor (); - WritePS (mpPageBody, "eofill\n"); - } - - // restore the current path - if( maFillColor.Is() && maLineColor.Is()) - PSGRestore(); - - // now draw outlines - if( maLineColor.Is() ) - { - PSSetColor (maLineColor); - PSSetColor (); - PSSetLineWidth (); - WritePS (mpPageBody, "stroke\n"); - } -} - -/* - * Bezier Polygon Drawing methods. - */ - -void -PrinterGfx::DrawPolyLineBezier (sal_uInt32 nPoints, const Point* pPath, const PolyFlags* pFlgAry) -{ - const sal_uInt32 nBezString= 1024; - char pString[nBezString]; - - if ( nPoints <= 1 || !maLineColor.Is() || !pPath ) - return; - - PSSetColor (maLineColor); - PSSetColor (); - PSSetLineWidth (); - - snprintf(pString, nBezString, "%" SAL_PRIdINT64 " %" SAL_PRIdINT64 " moveto\n", sal_Int64(pPath[0].X()), sal_Int64(pPath[0].Y())); - WritePS(mpPageBody, pString); - - // Handle the drawing of mixed lines mixed with curves - // - a normal point followed by a normal point is a line - // - a normal point followed by 2 control points and a normal point is a curve - for (unsigned int i=1; i<nPoints;) - { - if (pFlgAry[i] != PolyFlags::Control) //If the next point is a PolyFlags::Normal, we're drawing a line - { - snprintf(pString, nBezString, "%" SAL_PRIdINT64 " %" SAL_PRIdINT64 " lineto\n", sal_Int64(pPath[i].X()), sal_Int64(pPath[i].Y())); - i++; - } - else //Otherwise we're drawing a spline - { - if (i+2 >= nPoints) - return; //Error: wrong sequence of control/normal points somehow - if ((pFlgAry[i] == PolyFlags::Control) && (pFlgAry[i+1] == PolyFlags::Control) && - (pFlgAry[i+2] != PolyFlags::Control)) - { - snprintf(pString, nBezString, "%" SAL_PRIdINT64 " %" SAL_PRIdINT64 " %" SAL_PRIdINT64 " %" SAL_PRIdINT64 " %" SAL_PRIdINT64 " %" SAL_PRIdINT64 " curveto\n", - sal_Int64(pPath[i].X()), sal_Int64(pPath[i].Y()), - sal_Int64(pPath[i+1].X()), sal_Int64(pPath[i+1].Y()), - sal_Int64(pPath[i+2].X()), sal_Int64(pPath[i+2].Y())); - } - else - { - OSL_FAIL( "PrinterGfx::DrawPolyLineBezier: Strange output" ); - } - i+=3; - } - WritePS(mpPageBody, pString); - } - - // now draw outlines - WritePS (mpPageBody, "stroke\n"); -} - -void -PrinterGfx::DrawPolygonBezier (sal_uInt32 nPoints, const Point* pPath, const PolyFlags* pFlgAry) -{ - const sal_uInt32 nBezString = 1024; - char pString[nBezString]; - // premature end of operation - if (nPoints <= 0 || (pPath == nullptr) || !(maFillColor.Is() || maLineColor.Is())) - return; - - snprintf(pString, nBezString, "%" SAL_PRIdINT64 " %" SAL_PRIdINT64 " moveto\n", sal_Int64(pPath[0].X()), sal_Int64(pPath[0].Y())); - WritePS(mpPageBody, pString); //Move to the starting point for the PolyPolygon - for (unsigned int i=1; i < nPoints;) - { - if (pFlgAry[i] != PolyFlags::Control) - { - snprintf(pString, nBezString, "%" SAL_PRIdINT64 " %" SAL_PRIdINT64 " lineto\n", - sal_Int64(pPath[i].X()), sal_Int64(pPath[i].Y())); - WritePS(mpPageBody, pString); - i++; - } - else - { - if (i+2 >= nPoints) - return; //Error: wrong sequence of control/normal points somehow - if ((pFlgAry[i] == PolyFlags::Control) && (pFlgAry[i+1] == PolyFlags::Control) && - (pFlgAry[i+2] != PolyFlags::Control)) - { - snprintf(pString, nBezString, "%" SAL_PRIdINT64 " %" SAL_PRIdINT64 " %" SAL_PRIdINT64 " %" SAL_PRIdINT64 " %" SAL_PRIdINT64 " %" SAL_PRIdINT64 " curveto\n", - sal_Int64(pPath[i].X()), sal_Int64(pPath[i].Y()), - sal_Int64(pPath[i+1].X()), sal_Int64(pPath[i+1].Y()), - sal_Int64(pPath[i+2].X()), sal_Int64(pPath[i+2].Y())); - WritePS(mpPageBody, pString); - } - else - { - OSL_FAIL( "PrinterGfx::DrawPolygonBezier: Strange output" ); - } - i+=3; - } - } - - // if fill and stroke, save the current path - if( maFillColor.Is() && maLineColor.Is()) - PSGSave(); - - if (maFillColor.Is ()) - { - PSSetColor (maFillColor); - PSSetColor (); - WritePS (mpPageBody, "eofill\n"); - } - - // restore the current path - if( maFillColor.Is() && maLineColor.Is()) - PSGRestore(); -} - -void -PrinterGfx::DrawPolyPolygonBezier (sal_uInt32 nPoly, const sal_uInt32 * pPoints, const Point* const * pPtAry, const PolyFlags* const* pFlgAry) -{ - const sal_uInt32 nBezString = 1024; - char pString[nBezString]; - if ( !nPoly || !pPtAry || !pPoints || !(maFillColor.Is() || maLineColor.Is())) - return; - - for (unsigned int i=0; i<nPoly;i++) - { - sal_uInt32 nPoints = pPoints[i]; - // sanity check - if( nPoints == 0 || pPtAry[i] == nullptr ) - continue; - - snprintf(pString, nBezString, "%" SAL_PRIdINT64 " %" SAL_PRIdINT64 " moveto\n", ... etc. - the rest is truncated