1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #include "psputil.hxx"
21 #include "glyphset.hxx"
22
23 #include <unx/printergfx.hxx>
24 #include <unx/fontmanager.hxx>
25
26 using namespace psp ;
27
28 /*
29 * implement text handling printer routines,
30 */
31
SetFont(sal_Int32 nFontID,sal_Int32 nHeight,sal_Int32 nWidth,sal_Int32 nAngle,bool bVertical,bool bArtItalic,bool bArtBold)32 void PrinterGfx::SetFont(
33 sal_Int32 nFontID,
34 sal_Int32 nHeight,
35 sal_Int32 nWidth,
36 sal_Int32 nAngle,
37 bool bVertical,
38 bool bArtItalic,
39 bool bArtBold
40 )
41 {
42 // font and encoding will be set by drawText again immediately
43 // before PSShowText
44 mnFontID = nFontID;
45 maVirtualStatus.maFont.clear();
46 maVirtualStatus.maEncoding = RTL_TEXTENCODING_DONTKNOW;
47 maVirtualStatus.mnTextHeight = nHeight;
48 maVirtualStatus.mnTextWidth = nWidth;
49 maVirtualStatus.mbArtItalic = bArtItalic;
50 maVirtualStatus.mbArtBold = bArtBold;
51 mnTextAngle = nAngle;
52 mbTextVertical = bVertical;
53 }
54
drawGlyph(const Point & rPoint,sal_GlyphId aGlyphId)55 void PrinterGfx::drawGlyph(const Point& rPoint,
56 sal_GlyphId aGlyphId)
57 {
58
59 // draw the string
60 // search for a glyph set matching the set font
61 bool bGlyphFound = false;
62 for (auto & elem : maPS3Font)
63 if ( (elem.GetFontID() == mnFontID)
64 && (elem.IsVertical() == mbTextVertical))
65 {
66 elem.DrawGlyph (*this, rPoint, aGlyphId);
67 bGlyphFound = true;
68 break;
69 }
70
71 // not found ? create a new one
72 if (!bGlyphFound)
73 {
74 maPS3Font.emplace_back(mnFontID, mbTextVertical);
75 maPS3Font.back().DrawGlyph (*this, rPoint, aGlyphId);
76 }
77 }
78
DrawGlyph(const Point & rPoint,const GlyphItem & rGlyph)79 void PrinterGfx::DrawGlyph(const Point& rPoint,
80 const GlyphItem& rGlyph)
81 {
82 // move and rotate the user coordinate system
83 // avoid the gsave/grestore for the simple cases since it allows
84 // reuse of the current font if it hasn't changed
85 sal_Int32 nCurrentTextAngle = mnTextAngle;
86 Point aPoint( rPoint );
87
88 if (nCurrentTextAngle != 0)
89 {
90 PSGSave ();
91 PSTranslate (rPoint);
92 PSRotate (nCurrentTextAngle);
93 mnTextAngle = 0;
94 aPoint = Point( 0, 0 );
95 }
96
97 if (mbTextVertical && rGlyph.IsVertical())
98 {
99 sal_Int32 nTextHeight = maVirtualStatus.mnTextHeight;
100 sal_Int32 nTextWidth = maVirtualStatus.mnTextWidth ? maVirtualStatus.mnTextWidth : maVirtualStatus.mnTextHeight;
101 sal_Int32 nAscend = mrFontMgr.getFontAscend( mnFontID );
102 sal_Int32 nDescend = mrFontMgr.getFontDescend( mnFontID );
103
104 nDescend = nDescend * nTextHeight / 1000;
105 nAscend = nAscend * nTextHeight / 1000;
106
107 Point aRotPoint( -nDescend*nTextWidth/nTextHeight, nAscend*nTextWidth/nTextHeight );
108
109 // transform matrix to new individual direction
110 PSGSave ();
111 GraphicsStatus aSaveStatus = maVirtualStatus;
112 // switch font aspect
113 maVirtualStatus.mnTextWidth = nTextHeight;
114 maVirtualStatus.mnTextHeight = nTextWidth;
115 if( aPoint.X() || aPoint.Y() )
116 PSTranslate( aPoint );
117 PSRotate (900);
118 // draw the rotated glyph
119 drawGlyph(aRotPoint, rGlyph.glyphId());
120
121 // restore previous state
122 maVirtualStatus = aSaveStatus;
123 PSGRestore();
124 }
125 else
126 drawGlyph(aPoint, rGlyph.glyphId());
127
128 // restore the user coordinate system
129 if (nCurrentTextAngle != 0)
130 {
131 PSGRestore ();
132 mnTextAngle = nCurrentTextAngle;
133 }
134 }
135
136 /*
137 * spool the converted truetype fonts to the page header after the page body is
138 * complete
139 * for Type1 fonts spool additional reencoding vectors that are necessary to access the
140 * whole font
141 */
142
143 void
OnEndJob()144 PrinterGfx::OnEndJob ()
145 {
146 maPS3Font.clear();
147 }
148
149 void
writeResources(osl::File * pFile,std::vector<OString> & rSuppliedFonts)150 PrinterGfx::writeResources( osl::File* pFile, std::vector< OString >& rSuppliedFonts )
151 {
152 // write glyphsets and reencodings
153 for (auto & PS3Font : maPS3Font)
154 {
155 PS3Font.PSUploadFont (*pFile, *this, mbUploadPS42Fonts, rSuppliedFonts );
156 }
157 }
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
159