Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / unx / generic / print / text_gfx.cxx
blobd3153952b0a692f49cfadadf3b333c708cc4b98b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "psputil.hxx"
21 #include "glyphset.hxx"
23 #include <unx/printergfx.hxx>
24 #include <unx/fontmanager.hxx>
26 using namespace psp ;
29 * implement text handling printer routines,
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
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;
55 void PrinterGfx::drawGlyph(const Point& rPoint,
56 sal_GlyphId aGlyphId)
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))
66 elem.DrawGlyph (*this, rPoint, aGlyphId);
67 bGlyphFound = true;
68 break;
71 // not found ? create a new one
72 if (!bGlyphFound)
74 maPS3Font.emplace_back(mnFontID, mbTextVertical);
75 maPS3Font.back().DrawGlyph (*this, rPoint, aGlyphId);
79 void PrinterGfx::DrawGlyph(const Point& rPoint,
80 const GlyphItem& rGlyph)
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 );
88 if (nCurrentTextAngle != 0)
90 PSGSave ();
91 PSTranslate (rPoint);
92 PSRotate (nCurrentTextAngle);
93 mnTextAngle = 0;
94 aPoint = Point( 0, 0 );
97 if (mbTextVertical && rGlyph.IsVertical())
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 );
104 nDescend = nDescend * nTextHeight / 1000;
105 nAscend = nAscend * nTextHeight / 1000;
107 Point aRotPoint( -nDescend*nTextWidth/nTextHeight, nAscend*nTextWidth/nTextHeight );
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());
121 // restore previous state
122 maVirtualStatus = aSaveStatus;
123 PSGRestore();
125 else
126 drawGlyph(aPoint, rGlyph.glyphId());
128 // restore the user coordinate system
129 if (nCurrentTextAngle != 0)
131 PSGRestore ();
132 mnTextAngle = nCurrentTextAngle;
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
143 void
144 PrinterGfx::OnEndJob ()
146 maPS3Font.clear();
149 void
150 PrinterGfx::writeResources( osl::File* pFile, std::vector< OString >& rSuppliedFonts )
152 // write glyphsets and reencodings
153 for (auto & PS3Font : maPS3Font)
155 PS3Font.PSUploadFont (*pFile, *this, mbUploadPS42Fonts, rSuppliedFonts );
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */