1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
|
/* -*- 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 <math.h>
#include "psputil.hxx"
#include "glyphset.hxx"
#include "generic/printergfx.hxx"
#include "fontmanager.hxx"
#include "vcl/helper.hxx"
#include "osl/thread.h"
#include "sal/alloca.h"
using namespace psp ;
namespace psp {
/*
container for a font and its helper fonts:
1st is the font itself
2nd is a fallback font, usually a font with unicode glyph repertoir (e.g. andale)
symbol fonts (adobe-fontspecific) may need special glyphmapping
(symbol page vc. latin page)
*/
class Font2
{
private:
#define Font2Size 2
fontID mpFont [Font2Size];
bool mbSymbol;
public:
fontID GetFont (int nIdx) const
{ return nIdx < Font2Size ? mpFont[nIdx] : -1 ; }
bool IsSymbolFont () const
{ return mbSymbol; }
Font2 (const PrinterGfx &rGfx);
~Font2 () {}
};
Font2::Font2(const PrinterGfx &rGfx)
{
mpFont[0] = rGfx.GetFontID();
mpFont[1] = rGfx.getFallbackID();
PrintFontManager &rMgr = PrintFontManager::get();
mbSymbol = mpFont[0] != -1 ?
rMgr.getFontEncoding(mpFont[0]) == RTL_TEXTENCODING_SYMBOL : false;
}
} // namespace psp
static int getVerticalDeltaAngle( sal_Unicode nChar )
{
int nRotation = GetVerticalFlags(nChar);
if (nRotation == GF_ROTR)
return -900;
if (nRotation == GF_ROTL)
return 900;
return 0;
}
void
PrinterGfx::PSUploadPS1Font (sal_Int32 nFontID)
{
std::list< sal_Int32 >::iterator aFont;
// already in the document header ?
for (aFont = maPS1Font.begin(); aFont != maPS1Font.end(); ++aFont )
if( nFontID == *aFont )
return;
// no occurrenc yet, mark for download
// add the fontid to the list
maPS1Font.push_back (nFontID);
}
/*
* implement text handling printer routines,
*/
sal_uInt16
PrinterGfx::SetFont(
sal_Int32 nFontID,
sal_Int32 nHeight,
sal_Int32 nWidth,
sal_Int32 nAngle,
bool bVertical,
bool bArtItalic,
bool bArtBold
)
{
// font and encoding will be set by drawText again immediately
// before PSShowText
mnFontID = nFontID;
maVirtualStatus.maFont = OString();
maVirtualStatus.maEncoding = RTL_TEXTENCODING_DONTKNOW;
maVirtualStatus.mnTextHeight = nHeight;
maVirtualStatus.mnTextWidth = nWidth;
maVirtualStatus.mbArtItalic = bArtItalic;
maVirtualStatus.mbArtBold = bArtBold;
mnTextAngle = nAngle;
mbTextVertical = bVertical;
return 0;
}
void PrinterGfx::drawGlyphs(
const Point& rPoint,
sal_GlyphId* pGlyphIds,
sal_Unicode* pUnicodes,
sal_Int16 nLen,
sal_Int32* pDeltaArray
)
{
// draw the string
// search for a glyph set matching the set font
std::list< GlyphSet >::iterator aIter;
for (aIter = maPS3Font.begin(); aIter != maPS3Font.end(); ++aIter)
if ( ((*aIter).GetFontID() == mnFontID)
&& ((*aIter).IsVertical() == mbTextVertical))
{
(*aIter).DrawGlyphs (*this, rPoint, pGlyphIds, pUnicodes, nLen, pDeltaArray);
break;
}
// not found ? create a new one
if (aIter == maPS3Font.end())
{
maPS3Font.push_back (GlyphSet(mnFontID, mbTextVertical));
maPS3Font.back().DrawGlyphs (*this, rPoint, pGlyphIds, pUnicodes, nLen, pDeltaArray);
}
}
void PrinterGfx::DrawGlyphs(
const Point& rPoint,
sal_GlyphId* pGlyphIds,
sal_Unicode* pUnicodes,
sal_Int16 nLen,
sal_Int32* pDeltaArray
)
{
if( nLen <= 0 )
return;
if ( !mrFontMgr.isFontDownloadingAllowedForPrinting( mnFontID ) )
{
LicenseWarning(rPoint, pUnicodes, nLen, pDeltaArray);
return;
}
if( mrFontMgr.getFontType( mnFontID ) != fonttype::TrueType )
{
DrawText( rPoint, pUnicodes, nLen, pDeltaArray );
return;
}
// move and rotate the user coordinate system
// avoid the gsave/grestore for the simple cases since it allows
// reuse of the current font if it hasn't changed
sal_Int32 nCurrentTextAngle = mnTextAngle;
Point aPoint( rPoint );
if (nCurrentTextAngle != 0)
{
PSGSave ();
PSTranslate (rPoint);
PSRotate (nCurrentTextAngle);
mnTextAngle = 0;
aPoint = Point( 0, 0 );
}
if( mbTextVertical )
{
// vertical glyphs can have an additional rotation ... sigh.
// so break up text in chunks of normal glyphs and print out
// specially rotated glyphs extra
sal_GlyphId* pTempGlyphIds = (sal_GlyphId*)alloca(sizeof(sal_Int32)*nLen);
sal_Int32* pTempDelta = (sal_Int32*)alloca(sizeof(sal_Int32)*nLen);
sal_Unicode* pTempUnicodes = (sal_Unicode*)alloca(sizeof(sal_Unicode)*nLen);
sal_Int16 nTempLen = 0;
sal_Int32 nTempFirstDelta = 0;
Point aRotPoint;
sal_Int32 nTextHeight = maVirtualStatus.mnTextHeight;
sal_Int32 nTextWidth = maVirtualStatus.mnTextWidth ? maVirtualStatus.mnTextWidth : maVirtualStatus.mnTextHeight;
sal_Int32 nAscend = mrFontMgr.getFontAscend( mnFontID );
sal_Int32 nDescend = mrFontMgr.getFontDescend( mnFontID );
nDescend = nDescend * nTextHeight / 1000;
nAscend = nAscend * nTextHeight / 1000;
for( sal_Int16 i = 0; i < nLen; i++ )
{
const sal_GlyphId nRot = pGlyphIds[i] & GF_ROTMASK;
if( nRot == GF_NONE )
{
pTempUnicodes[nTempLen] = pUnicodes[i];
pTempGlyphIds[nTempLen] = pGlyphIds[i];
if( nTempLen > 0 )
pTempDelta[nTempLen-1] = pDeltaArray[i-1]-nTempFirstDelta;
else
{
// the first element in pDeltaArray shows
// the offset of the second character
// so if the first glyph is normal
// then we do not need to move the delta indices
// else we have to move them down by one and
// recalculate aPoint and all deltas
if( i != 0 )
nTempFirstDelta = pDeltaArray[ i-1 ];
}
nTempLen++;
}
else
{
sal_Int32 nOffset = i > 0 ? pDeltaArray[i-1] : 0;
sal_Int32 nRotAngle = 0;
switch( nRot )
{
case GF_ROTR:
nRotAngle = 2700;
aRotPoint = Point( -nAscend*nTextWidth/nTextHeight, -nDescend*nTextWidth/nTextHeight - nOffset );
break;
case GF_VERT:
nRotAngle = 1800;
aRotPoint = Point( -nOffset, (nAscend+nDescend) );
break;
case GF_ROTL:
nRotAngle = 900;
aRotPoint = Point( -nDescend*nTextWidth/nTextHeight, nOffset + nAscend*nTextWidth/nTextHeight );
break;
}
sal_GlyphId nRotGlyphId = pGlyphIds[i];
sal_Unicode nRotUnicode = pUnicodes[i];
sal_Int32 nRotDelta = 0;
// transform matrix to new individual direction
PSGSave ();
GraphicsStatus aSaveStatus = maVirtualStatus;
if( nRot != 2 ) // switch font aspect
{
maVirtualStatus.mnTextWidth = nTextHeight;
maVirtualStatus.mnTextHeight = nTextWidth;
}
if( aPoint.X() || aPoint.Y() )
PSTranslate( aPoint );
PSRotate (nRotAngle);
// draw the rotated glyph
drawGlyphs( aRotPoint, &nRotGlyphId, &nRotUnicode, 1, &nRotDelta );
// restore previous state
maVirtualStatus = aSaveStatus;
PSGRestore();
}
}
pGlyphIds = pTempGlyphIds;
pUnicodes = pTempUnicodes;
pDeltaArray = pTempDelta;
nLen = nTempLen;
aPoint.X() += nTempFirstDelta;
}
if( nLen > 0 )
drawGlyphs( aPoint, pGlyphIds, pUnicodes, nLen, pDeltaArray );
// restore the user coordinate system
if (nCurrentTextAngle != 0)
{
PSGRestore ();
mnTextAngle = nCurrentTextAngle;
}
}
void
PrinterGfx::DrawText (
const Point& rPoint,
const sal_Unicode* pStr,
sal_Int16 nLen,
const sal_Int32* pDeltaArray
)
{
fontID nRestoreFont = mnFontID;
// setup font[substitutes] and map the string into the symbol area in case of
// symbol font
Font2 aFont(*this);
sal_Unicode *pEffectiveStr;
if ( aFont.IsSymbolFont() )
{
pEffectiveStr = (sal_Unicode*)alloca(nLen * sizeof(pStr[0]));
for (int i = 0; i < nLen; i++)
pEffectiveStr[i] = pStr[i] < 256 ? pStr[i] + 0xF000 : pStr[i];
}
else
{
pEffectiveStr = const_cast<sal_Unicode*>(pStr);
}
fontID *pFontMap = (fontID*) alloca(nLen * sizeof(fontID));
sal_Int32 *pCharWidth = (sal_Int32*) alloca(nLen * sizeof(sal_Int32));
for( int n = 0; n < nLen; n++ )
{
CharacterMetric aBBox;
pFontMap[n] = getCharMetric (aFont, pEffectiveStr[n], &aBBox);
pCharWidth[n] = getCharWidth (mbTextVertical, pEffectiveStr[n], &aBBox);
}
// setup a new delta array, use virtual resolution of 1000
sal_Int32* pNewDeltaArray = (sal_Int32*)alloca( sizeof( sal_Int32 )*nLen );
if ( pDeltaArray != 0)
{
for (int i = 0; i < nLen - 1; i++)
pNewDeltaArray[i] = 1000 * pDeltaArray[i];
pNewDeltaArray[nLen - 1] = 0;
}
else
{
pNewDeltaArray[0] = pCharWidth[0];
for (int i = 1; i < nLen; i++)
pNewDeltaArray[i] = pNewDeltaArray[i-1] + pCharWidth[i];
}
// move and rotate the user coordinate system
// avoid the gsave/grestore for the simple cases since it allows
// reuse of the current font if it hasn't changed
sal_Int32 nCurrentTextAngle = mnTextAngle;
sal_Int32 nCurrentPointX;
sal_Int32 nCurrentPointY;
if (nCurrentTextAngle != 0)
{
PSGSave ();
PSTranslate (rPoint);
PSRotate (nCurrentTextAngle);
mnTextAngle = 0;
nCurrentPointX = 0;
nCurrentPointY = 0;
}
else
{
nCurrentPointX = rPoint.X();
nCurrentPointY = rPoint.Y();
}
// draw the string
sal_Int32 nDelta = 0;
for (int nTo = 0; nTo < nLen; )
{
int nFrom = nTo;
fontID nFont = pFontMap[ nFrom ];
while ((nTo < nLen) && (nFont == pFontMap[nTo]))
{
pNewDeltaArray[ nTo ] = (sal_Int32)(((0.5 + pNewDeltaArray[ nTo ]) / 1000.0) - nDelta);
nTo++ ;
}
SetFont( nFont,
maVirtualStatus.mnTextHeight, maVirtualStatus.mnTextWidth,
mnTextAngle,
mbTextVertical,
maVirtualStatus.mbArtItalic,
maVirtualStatus.mbArtBold
);
if (mbTextVertical)
{
drawVerticalizedText(
Point(nCurrentPointX + nDelta, nCurrentPointY),
pEffectiveStr + nFrom, nTo - nFrom,
pNewDeltaArray + nFrom );
}
else
{
drawText(
Point(nCurrentPointX + nDelta, nCurrentPointY),
pEffectiveStr + nFrom, nTo - nFrom,
pDeltaArray == NULL ? NULL : pNewDeltaArray + nFrom );
}
nDelta += pNewDeltaArray[ nTo - 1 ];
}
// restore the user coordinate system
if (nCurrentTextAngle != 0)
{
PSGRestore ();
mnTextAngle = nCurrentTextAngle;
}
// restore the original font settings
SetFont( nRestoreFont,
maVirtualStatus.mnTextHeight, maVirtualStatus.mnTextWidth,
mnTextAngle, mbTextVertical,
maVirtualStatus.mbArtItalic,
maVirtualStatus.mbArtBold
);
}
void PrinterGfx::drawVerticalizedText(
const Point& rPoint,
const sal_Unicode* pStr,
sal_Int16 nLen,
const sal_Int32* pDeltaArray
)
{
sal_Int32* pDelta = (sal_Int32*)alloca( nLen * sizeof(sal_Int32) );
int nTextScale = maVirtualStatus.mnTextWidth ? maVirtualStatus.mnTextWidth : maVirtualStatus.mnTextHeight;
int nNormalAngle = mnTextAngle;
int nDeltaAngle, nLastPos = 0;
double fSin = sin( -2.0*M_PI*nNormalAngle/3600 );
double fCos = cos( -2.0*M_PI*nNormalAngle/3600 );
PrintFontManager &rMgr = PrintFontManager::get();
PrintFontInfo aInfo;
rMgr.getFontInfo( mnFontID, aInfo );
bool* pGsubFlags = (bool*)alloca( nLen * sizeof(bool) );
rMgr.hasVerticalSubstitutions( mnFontID, pStr, nLen, pGsubFlags );
Point aPoint( rPoint );
for( int i = 0; i < nLen; )
{
while( ( nDeltaAngle = getVerticalDeltaAngle( pStr[i] ) ) == 0 && i < nLen )
i++;
if( i <= nLen && i > nLastPos )
{
for( int n = nLastPos; n < i; n++ )
pDelta[n] = pDeltaArray[n] - (aPoint.X() - rPoint.X() );
SetFont( mnFontID,
maVirtualStatus.mnTextHeight, maVirtualStatus.mnTextWidth,
nNormalAngle, mbTextVertical,
maVirtualStatus.mbArtItalic,
maVirtualStatus.mbArtBold );
drawText( aPoint, pStr + nLastPos, i - nLastPos, pDelta + nLastPos );
aPoint.X() = (sal_Int32)(rPoint.X() + ((double)pDeltaArray[i-1] * fCos));
aPoint.Y() = (sal_Int32)(rPoint.Y() + ((double)pDeltaArray[i-1] * fSin));
}
if( i < nLen )
{
int nOldWidth = maVirtualStatus.mnTextWidth;
int nOldHeight = maVirtualStatus.mnTextHeight;
SetFont( mnFontID,
nTextScale,
maVirtualStatus.mnTextHeight,
nNormalAngle + nDeltaAngle,
mbTextVertical,
maVirtualStatus.mbArtItalic,
maVirtualStatus.mbArtBold );
double nA = nTextScale * aInfo.m_nAscend / 1000.0;
double nD = nTextScale * aInfo.m_nDescend / 1000.0;
double fStretch = (double)maVirtualStatus.mnTextWidth / maVirtualStatus.mnTextHeight;
if( !pGsubFlags[i] )
nD *= fStretch;
Point aPos( aPoint );
switch( nDeltaAngle )
{
case +900:
aPos.X() += (sal_Int32)(+nA * fCos + nD * fSin);
aPos.Y() += (sal_Int32)(-nA * fSin + nD * fCos);
break;
case -900:
aPos.X() += (sal_Int32)(+nA * fSin + nD * fCos);
aPos.Y() += (sal_Int32)(-(nTextScale*fStretch - nD) * fCos);
break;
}
drawText( aPos, pStr+i, 1, NULL );
if( i < nLen-1 && pDeltaArray )
{
aPoint.X() = (sal_Int32)(rPoint.X() + ((double)pDeltaArray[i] * fCos));
aPoint.Y() = (sal_Int32)(rPoint.Y() + ((double)pDeltaArray[i] * fSin));
}
// swap text width/height again
SetFont( mnFontID,
nOldHeight,
nOldWidth,
nNormalAngle,
mbTextVertical,
maVirtualStatus.mbArtItalic,
maVirtualStatus.mbArtBold );
}
i++;
nLastPos = i;
}
mnTextAngle = nNormalAngle;
}
void
PrinterGfx::LicenseWarning(const Point& rPoint, const sal_Unicode* pStr,
sal_Int16 nLen, const sal_Int32* pDeltaArray)
{
// treat it like a builtin font in case a user has that font also in the
// printer. This is not so unlikely as it may seem; no print embedding
// licensed fonts are often used (or so they say) in companies:
// they are installed on displays and printers, but get not embedded in
// print files or documents because they are not licensed for use outside
// the company.
OString aMessage( "The font " );
aMessage += OUStringToOString( mrFontMgr.getPSName(mnFontID),
RTL_TEXTENCODING_ASCII_US );
aMessage += " could not be downloaded\nbecause its license does not allow for that";
PSComment( aMessage.getStr() );
OString aFontName = OUStringToOString(
mrFontMgr.getPSName(mnFontID),
RTL_TEXTENCODING_ASCII_US);
PSSetFont (aFontName, RTL_TEXTENCODING_ISO_8859_1);
sal_Size nSize = 4 * nLen;
unsigned char* pBuffer = (unsigned char*)alloca (nSize* sizeof(unsigned char));
ConverterFactory &rCvt = GetConverterFactory ();
nSize = rCvt.Convert (pStr, nLen, pBuffer, nSize, RTL_TEXTENCODING_ISO_8859_1);
PSMoveTo (rPoint);
PSShowText (pBuffer, nLen, nSize, pDeltaArray);
}
void
PrinterGfx::drawText(
const Point& rPoint,
const sal_Unicode* pStr,
sal_Int16 nLen,
const sal_Int32* pDeltaArray
)
{
if (!(nLen > 0))
return;
fonttype::type eType = mrFontMgr.getFontType (mnFontID);
if (eType == fonttype::Type1)
PSUploadPS1Font (mnFontID);
if ( eType == fonttype::TrueType
&& !mrFontMgr.isFontDownloadingAllowedForPrinting(mnFontID))
{
LicenseWarning(rPoint, pStr, nLen, pDeltaArray);
return;
}
if( mrFontMgr.getUseOnlyFontEncoding( mnFontID ) )
{
GlyphSet aGSet( mnFontID, mbTextVertical );
aGSet.DrawText( *this, rPoint, pStr, nLen, pDeltaArray );
return;
}
// search for a glyph set matching the set font
std::list< GlyphSet >::iterator aIter;
for (aIter = maPS3Font.begin(); aIter != maPS3Font.end(); ++aIter)
if ( ((*aIter).GetFontID() == mnFontID)
&& ((*aIter).IsVertical() == mbTextVertical))
{
(*aIter).DrawText (*this, rPoint, pStr, nLen, pDeltaArray);
break;
}
// not found ? create a new one
if (aIter == maPS3Font.end())
{
maPS3Font.push_back (GlyphSet(mnFontID, mbTextVertical));
maPS3Font.back().DrawText (*this, rPoint, pStr, nLen, pDeltaArray);
}
}
int
PrinterGfx::getCharWidth (bool b_vert, sal_Unicode n_char, CharacterMetric *p_bbox)
{
b_vert = b_vert && (getVerticalDeltaAngle(n_char) != 0);
int w = b_vert ? p_bbox->height : p_bbox->width;
w *= maVirtualStatus.mnTextWidth ? maVirtualStatus.mnTextWidth : maVirtualStatus.mnTextHeight;
return w;
}
fontID
PrinterGfx::getCharMetric (const Font2 &rFont, sal_Unicode n_char, CharacterMetric *p_bbox)
{
p_bbox->width = -1;
p_bbox->height = -1;
for (fontID n = 0; n < Font2Size; n++)
{
fontID n_font = rFont.GetFont(n);
if (n_font != -1)
mrFontMgr.getMetrics( n_font, n_char, n_char, p_bbox );
if (p_bbox->width >= 0 && p_bbox->height >= 0)
return n_font;
}
if (n_char != '?')
return getCharMetric (rFont, '?', p_bbox);
return rFont.GetFont(0) != -1 ? rFont.GetFont(0) : rFont.GetFont(1);
}
sal_Int32
PrinterGfx::GetCharWidth (sal_Unicode nFrom, sal_Unicode nTo, long *pWidthArray)
{
Font2 aFont(*this);
if (aFont.IsSymbolFont() && (nFrom < 256) && (nTo < 256))
{
nFrom += 0xF000;
nTo += 0xF000;
}
for( int n = 0; n < (nTo - nFrom + 1); n++ )
{
CharacterMetric aBBox;
getCharMetric (aFont, n + nFrom, &aBBox);
pWidthArray[n] = getCharWidth (mbTextVertical, n + nFrom, &aBBox);
}
// returned metrics have postscript precision
return 1000;
}
/*
* spool the converted truetype fonts to the page header after the page body is
* complete
* for Type1 fonts spool additional reencoding vectors that are necessary to access the
* whole font
*/
void
PrinterGfx::OnEndPage ()
{
}
void
PrinterGfx::OnEndJob ()
{
maPS3Font.clear();
maPS1Font.clear();
}
void
PrinterGfx::writeResources( osl::File* pFile, std::list< OString >& rSuppliedFonts )
{
// write all type 1 fonts
std::list< sal_Int32 >::iterator aFont;
// already in the document header ?
for (aFont = maPS1Font.begin(); aFont != maPS1Font.end(); ++aFont)
{
const OString& rSysPath (mrFontMgr.getFontFileSysPath(*aFont) );
OUString aUNCPath;
osl::File::getFileURLFromSystemPath (OStringToOUString (rSysPath, osl_getThreadTextEncoding()), aUNCPath);
osl::File aFontFile (aUNCPath);
// provide the pfb or pfa font as a (pfa-)font resource
OString aPostScriptName =
OUStringToOString ( mrFontMgr.getPSName(*aFont),
RTL_TEXTENCODING_ASCII_US );
WritePS (pFile, "%%BeginResource: font ");
WritePS (pFile, aPostScriptName.getStr());
WritePS (pFile, "\n");
osl::File::RC nError = aFontFile.open(osl_File_OpenFlag_Read);
if (nError == osl::File::E_None)
{
convertPfbToPfa (aFontFile, *pFile);
aFontFile.close ();
char lastchar = '\n';
if (pFile->setPos(osl_Pos_Current, -1) == osl::FileBase::E_None)
{
sal_uInt64 uBytes(1);
pFile->read((void *)(&lastchar), uBytes, uBytes);
}
if (lastchar != '\n')
WritePS (pFile, "\n");
}
WritePS (pFile, "%%EndResource\n");
rSuppliedFonts.push_back( aPostScriptName );
}
// write glyphsets and reencodings
std::list< GlyphSet >::iterator aIter;
for (aIter = maPS3Font.begin(); aIter != maPS3Font.end(); ++aIter)
{
if (aIter->GetFontType() == fonttype::TrueType)
{
aIter->PSUploadFont (*pFile, *this, mbUploadPS42Fonts ? true : false, rSuppliedFonts );
}
else
{
aIter->PSUploadEncoding (pFile, *this);
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|