1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
29 * implement text handling printer routines,
32 void PrinterGfx::SetFont(
42 // font and encoding will be set by drawText again immediately
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
;
52 mbTextVertical
= bVertical
;
55 void PrinterGfx::drawGlyph(const Point
& rPoint
,
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
);
71 // not found ? create a new one
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)
92 PSRotate (nCurrentTextAngle
);
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
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
);
118 // draw the rotated glyph
119 drawGlyph(aRotPoint
, rGlyph
.glyphId());
121 // restore previous state
122 maVirtualStatus
= aSaveStatus
;
126 drawGlyph(aPoint
, rGlyph
.glyphId());
128 // restore the user coordinate system
129 if (nCurrentTextAngle
!= 0)
132 mnTextAngle
= nCurrentTextAngle
;
137 * spool the converted truetype fonts to the page header after the page body is
139 * for Type1 fonts spool additional reencoding vectors that are necessary to access the
144 PrinterGfx::OnEndJob ()
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: */