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
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
|
/* -*- 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 <vector>
#include <sal/types.h>
// for mmap etc.
#if defined( UNX )
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#endif
#include <comphelper/string.hxx>
#include <i18nlangtag/mslangid.hxx>
#include <vcl/bmpacc.hxx>
#include <vcl/jobdata.hxx>
#include <vcl/printerinfomanager.hxx>
#include <vcl/settings.hxx>
#include <vcl/svapp.hxx>
#include <vcl/sysdata.hxx>
#include <vcl/fontcharmap.hxx>
#include <config_cairo_canvas.h>
#include "fontsubset.hxx"
#include "generic/geninst.h"
#include "generic/genpspgraphics.h"
#include "generic/glyphcache.hxx"
#include "generic/printergfx.hxx"
#include "impfont.hxx"
#include "langboost.hxx"
#include "outfont.hxx"
#include "fontattributes.hxx"
#include "PhysicalFontCollection.hxx"
#include "PhysicalFontFace.hxx"
#include "salbmp.hxx"
#include "salprn.hxx"
#include <config_graphite.h>
#if ENABLE_GRAPHITE
#include <graphite_layout.hxx>
#include <graphite_serverfont.hxx>
#endif
using namespace psp;
// ----- Implementation of PrinterBmp by means of SalBitmap/BitmapBuffer ---------------
class SalPrinterBmp : public psp::PrinterBmp
{
private:
BitmapBuffer* mpBmpBuffer;
FncGetPixel mpFncGetPixel;
Scanline mpScanAccess;
sal_PtrDiff mnScanOffset;
sal_uInt32 ColorOf (BitmapColor& rColor) const;
sal_uInt8 GrayOf (BitmapColor& rColor) const;
public:
explicit SalPrinterBmp (BitmapBuffer* pBitmap);
virtual ~SalPrinterBmp ();
virtual sal_uInt32 GetPaletteColor (sal_uInt32 nIdx) const override;
virtual sal_uInt32 GetPaletteEntryCount () const override;
virtual sal_uInt32 GetPixelRGB (sal_uInt32 nRow, sal_uInt32 nColumn) const override;
virtual sal_uInt8 GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const override;
virtual sal_uInt8 GetPixelIdx (sal_uInt32 nRow, sal_uInt32 nColumn) const override;
virtual sal_uInt32 GetDepth () const override;
};
SalPrinterBmp::SalPrinterBmp (BitmapBuffer* pBuffer)
: mpBmpBuffer(pBuffer)
{
assert(mpBmpBuffer && "SalPrinterBmp::SalPrinterBmp () can't acquire Bitmap");
// calibrate scanline buffer
if( BMP_SCANLINE_ADJUSTMENT( mpBmpBuffer->mnFormat ) == BMP_FORMAT_TOP_DOWN )
{
mpScanAccess = mpBmpBuffer->mpBits;
mnScanOffset = mpBmpBuffer->mnScanlineSize;
}
else
{
mpScanAccess = mpBmpBuffer->mpBits
+ (mpBmpBuffer->mnHeight - 1) * mpBmpBuffer->mnScanlineSize;
mnScanOffset = - mpBmpBuffer->mnScanlineSize;
}
// request read access to the pixels
switch( BMP_SCANLINE_FORMAT( mpBmpBuffer->mnFormat ) )
{
case BMP_FORMAT_1BIT_MSB_PAL:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_1BIT_MSB_PAL; break;
case BMP_FORMAT_1BIT_LSB_PAL:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_1BIT_LSB_PAL; break;
case BMP_FORMAT_4BIT_MSN_PAL:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_4BIT_MSN_PAL; break;
case BMP_FORMAT_4BIT_LSN_PAL:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_4BIT_LSN_PAL; break;
case BMP_FORMAT_8BIT_PAL:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_8BIT_PAL; break;
case BMP_FORMAT_8BIT_TC_MASK:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_8BIT_TC_MASK; break;
case BMP_FORMAT_16BIT_TC_MSB_MASK:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_16BIT_TC_MSB_MASK; break;
case BMP_FORMAT_16BIT_TC_LSB_MASK:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_16BIT_TC_LSB_MASK; break;
case BMP_FORMAT_24BIT_TC_BGR:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_24BIT_TC_BGR; break;
case BMP_FORMAT_24BIT_TC_RGB:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_24BIT_TC_RGB; break;
case BMP_FORMAT_24BIT_TC_MASK:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_24BIT_TC_MASK; break;
case BMP_FORMAT_32BIT_TC_ABGR:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_ABGR; break;
case BMP_FORMAT_32BIT_TC_ARGB:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_ARGB; break;
case BMP_FORMAT_32BIT_TC_BGRA:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_BGRA; break;
case BMP_FORMAT_32BIT_TC_RGBA:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_RGBA; break;
case BMP_FORMAT_32BIT_TC_MASK:
mpFncGetPixel = BitmapReadAccess::GetPixelFor_32BIT_TC_MASK; break;
default:
OSL_FAIL("Error: SalPrinterBmp::SalPrinterBmp() unknown bitmap format");
mpFncGetPixel = nullptr;
break;
}
}
SalPrinterBmp::~SalPrinterBmp ()
{
}
sal_uInt32
SalPrinterBmp::GetDepth () const
{
sal_uInt32 nDepth;
switch (mpBmpBuffer->mnBitCount)
{
case 1:
nDepth = 1;
break;
case 4:
case 8:
nDepth = 8;
break;
case 16:
case 24:
case 32:
nDepth = 24;
break;
default:
nDepth = 1;
OSL_FAIL("Error: unsupported bitmap depth in SalPrinterBmp::GetDepth()");
break;
}
return nDepth;
}
sal_uInt32
SalPrinterBmp::ColorOf (BitmapColor& rColor) const
{
if (rColor.IsIndex())
return ColorOf (mpBmpBuffer->maPalette[rColor.GetIndex()]);
else
return ((rColor.GetBlue()) & 0x000000ff)
| ((rColor.GetGreen() << 8) & 0x0000ff00)
| ((rColor.GetRed() << 16) & 0x00ff0000);
}
sal_uInt8
SalPrinterBmp::GrayOf (BitmapColor& rColor) const
{
if (rColor.IsIndex())
return GrayOf (mpBmpBuffer->maPalette[rColor.GetIndex()]);
else
return ( rColor.GetBlue() * 28UL
+ rColor.GetGreen() * 151UL
+ rColor.GetRed() * 77UL ) >> 8;
}
sal_uInt32
SalPrinterBmp::GetPaletteEntryCount () const
{
return mpBmpBuffer->maPalette.GetEntryCount ();
}
sal_uInt32
SalPrinterBmp::GetPaletteColor (sal_uInt32 nIdx) const
{
return ColorOf (mpBmpBuffer->maPalette[nIdx]);
}
sal_uInt32
SalPrinterBmp::GetPixelRGB (sal_uInt32 nRow, sal_uInt32 nColumn) const
{
Scanline pScan = mpScanAccess + nRow * mnScanOffset;
BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask);
return ColorOf (aColor);
}
sal_uInt8
SalPrinterBmp::GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const
{
Scanline pScan = mpScanAccess + nRow * mnScanOffset;
BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask);
return GrayOf (aColor);
}
sal_uInt8
SalPrinterBmp::GetPixelIdx (sal_uInt32 nRow, sal_uInt32 nColumn) const
{
Scanline pScan = mpScanAccess + nRow * mnScanOffset;
BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask);
if (aColor.IsIndex())
return aColor.GetIndex();
else
return 0;
}
/*******************************************************
* GenPspGraphics *
*******************************************************/
GenPspGraphics::GenPspGraphics()
: m_pJobData( nullptr ),
m_pPrinterGfx( nullptr ),
m_bFontVertical( false ),
m_pInfoPrinter( nullptr )
{
for( int i = 0; i < MAX_FALLBACK; i++ )
m_pServerFont[i] = nullptr;
}
void GenPspGraphics::Init(psp::JobData* pJob, psp::PrinterGfx* pGfx,
SalInfoPrinter* pInfoPrinter)
{
m_pJobData = pJob;
m_pPrinterGfx = pGfx;
m_pInfoPrinter = pInfoPrinter;
SetLayout( SalLayoutFlags::NONE );
}
GenPspGraphics::~GenPspGraphics()
{
ReleaseFonts();
}
void GenPspGraphics::GetResolution( sal_Int32 &rDPIX, sal_Int32 &rDPIY )
{
if (m_pJobData != nullptr)
{
int x = m_pJobData->m_aContext.getRenderResolution();
rDPIX = x;
rDPIY = x;
}
}
sal_uInt16 GenPspGraphics::GetBitCount() const
{
return m_pPrinterGfx->GetBitCount();
}
long GenPspGraphics::GetGraphicsWidth() const
{
return 0;
}
void GenPspGraphics::ResetClipRegion()
{
m_pPrinterGfx->ResetClipRegion();
}
bool GenPspGraphics::setClipRegion( const vcl::Region& i_rClip )
{
// TODO: support polygonal clipregions here
RectangleVector aRectangles;
i_rClip.GetRegionRectangles(aRectangles);
m_pPrinterGfx->BeginSetClipRegion(aRectangles.size());
for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); ++aRectIter)
{
const long nW(aRectIter->GetWidth());
if(nW)
{
const long nH(aRectIter->GetHeight());
if(nH)
{
m_pPrinterGfx->UnionClipRegion(
aRectIter->Left(),
aRectIter->Top(),
nW,
nH);
}
}
}
m_pPrinterGfx->EndSetClipRegion();
//m_pPrinterGfx->BeginSetClipRegion( i_rClip.GetRectCount() );
//ImplRegionInfo aInfo;
//long nX, nY, nW, nH;
//bool bRegionRect = i_rClip.ImplGetFirstRect(aInfo, nX, nY, nW, nH );
//while( bRegionRect )
//{
// if ( nW && nH )
// {
// m_pPrinterGfx->UnionClipRegion( nX, nY, nW, nH );
// }
// bRegionRect = i_rClip.ImplGetNextRect( aInfo, nX, nY, nW, nH );
//}
//m_pPrinterGfx->EndSetClipRegion();
return true;
}
void GenPspGraphics::SetLineColor()
{
m_pPrinterGfx->SetLineColor ();
}
void GenPspGraphics::SetLineColor( SalColor nSalColor )
{
psp::PrinterColor aColor (SALCOLOR_RED (nSalColor),
SALCOLOR_GREEN (nSalColor),
SALCOLOR_BLUE (nSalColor));
m_pPrinterGfx->SetLineColor (aColor);
}
void GenPspGraphics::SetFillColor()
{
m_pPrinterGfx->SetFillColor ();
}
void GenPspGraphics::SetFillColor( SalColor nSalColor )
{
psp::PrinterColor aColor (SALCOLOR_RED (nSalColor),
SALCOLOR_GREEN (nSalColor),
SALCOLOR_BLUE (nSalColor));
m_pPrinterGfx->SetFillColor (aColor);
}
void GenPspGraphics::SetROPLineColor( SalROPColor )
{
DBG_ASSERT( false, "Error: PrinterGfx::SetROPLineColor() not implemented" );
}
void GenPspGraphics::SetROPFillColor( SalROPColor )
{
DBG_ASSERT( false, "Error: PrinterGfx::SetROPFillColor() not implemented" );
}
void GenPspGraphics::SetXORMode( bool bSet, bool )
{
(void)bSet;
DBG_ASSERT( !bSet, "Error: PrinterGfx::SetXORMode() not implemented" );
}
void GenPspGraphics::drawPixel( long nX, long nY )
{
m_pPrinterGfx->DrawPixel (Point(nX, nY));
}
void GenPspGraphics::drawPixel( long nX, long nY, SalColor nSalColor )
{
psp::PrinterColor aColor (SALCOLOR_RED (nSalColor),
SALCOLOR_GREEN (nSalColor),
SALCOLOR_BLUE (nSalColor));
m_pPrinterGfx->DrawPixel (Point(nX, nY), aColor);
}
void GenPspGraphics::drawLine( long nX1, long nY1, long nX2, long nY2 )
{
m_pPrinterGfx->DrawLine (Point(nX1, nY1), Point(nX2, nY2));
}
void GenPspGraphics::drawRect( long nX, long nY, long nDX, long nDY )
{
m_pPrinterGfx->DrawRect (Rectangle(Point(nX, nY), Size(nDX, nDY)));
}
void GenPspGraphics::drawPolyLine( sal_uInt32 nPoints, const SalPoint *pPtAry )
{
m_pPrinterGfx->DrawPolyLine (nPoints, reinterpret_cast<Point const *>(pPtAry));
}
void GenPspGraphics::drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry )
{
// Point must be equal to SalPoint! see vcl/inc/salgtype.hxx
m_pPrinterGfx->DrawPolygon (nPoints, reinterpret_cast<Point const *>(pPtAry));
}
void GenPspGraphics::drawPolyPolygon( sal_uInt32 nPoly,
const sal_uInt32 *pPoints,
PCONSTSALPOINT *pPtAry )
{
m_pPrinterGfx->DrawPolyPolygon (nPoly, pPoints, reinterpret_cast<const Point**>(pPtAry));
}
bool GenPspGraphics::drawPolyPolygon( const basegfx::B2DPolyPolygon&, double /*fTransparency*/ )
{
// TODO: implement and advertise OutDevSupport_B2DDraw support
return false;
}
bool GenPspGraphics::drawPolyLine(
const basegfx::B2DPolygon&,
double /*fTranspareny*/,
const basegfx::B2DVector& /*rLineWidths*/,
basegfx::B2DLineJoin /*eJoin*/,
css::drawing::LineCap /*eLineCap*/)
{
// TODO: a PS printer can draw B2DPolyLines almost directly
return false;
}
bool GenPspGraphics::drawPolyLineBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry )
{
m_pPrinterGfx->DrawPolyLineBezier (nPoints, reinterpret_cast<Point const *>(pPtAry), pFlgAry);
return true;
}
bool GenPspGraphics::drawPolygonBezier( sal_uInt32 nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry )
{
m_pPrinterGfx->DrawPolygonBezier (nPoints, reinterpret_cast<Point const *>(pPtAry), pFlgAry);
return true;
}
bool GenPspGraphics::drawPolyPolygonBezier( sal_uInt32 nPoly,
const sal_uInt32* pPoints,
const SalPoint* const* pPtAry,
const sal_uInt8* const* pFlgAry )
{
// Point must be equal to SalPoint! see vcl/inc/salgtype.hxx
m_pPrinterGfx->DrawPolyPolygonBezier (nPoly, pPoints, reinterpret_cast<Point const * const *>(pPtAry), pFlgAry);
return true;
}
void GenPspGraphics::invert( sal_uInt32,
const SalPoint*,
SalInvert )
{
DBG_ASSERT( false, "Error: PrinterGfx::Invert() not implemented" );
}
bool GenPspGraphics::drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uLong nSize )
{
return m_pPrinterGfx->DrawEPS( Rectangle( Point( nX, nY ), Size( nWidth, nHeight ) ), pPtr, nSize );
}
void GenPspGraphics::copyBits( const SalTwoRect&,
SalGraphics* )
{
OSL_FAIL( "Error: PrinterGfx::CopyBits() not implemented" );
}
void GenPspGraphics::copyArea ( long,long,long,long,long,long,sal_uInt16 )
{
OSL_FAIL( "Error: PrinterGfx::CopyArea() not implemented" );
}
void GenPspGraphics::drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap )
{
Rectangle aSrc (Point(rPosAry.mnSrcX, rPosAry.mnSrcY),
Size(rPosAry.mnSrcWidth, rPosAry.mnSrcHeight));
Rectangle aDst (Point(rPosAry.mnDestX, rPosAry.mnDestY),
Size(rPosAry.mnDestWidth, rPosAry.mnDestHeight));
BitmapBuffer* pBuffer= const_cast<SalBitmap&>(rSalBitmap).AcquireBuffer(BITMAP_READ_ACCESS);
SalPrinterBmp aBmp (pBuffer);
m_pPrinterGfx->DrawBitmap (aDst, aSrc, aBmp);
const_cast<SalBitmap&>(rSalBitmap).ReleaseBuffer (pBuffer, BITMAP_READ_ACCESS);
}
void GenPspGraphics::drawBitmap( const SalTwoRect&,
const SalBitmap&,
const SalBitmap& )
{
OSL_FAIL("Error: no PrinterGfx::DrawBitmap() for transparent bitmap");
}
void GenPspGraphics::drawMask( const SalTwoRect&,
const SalBitmap &,
SalColor )
{
OSL_FAIL("Error: PrinterGfx::DrawMask() not implemented");
}
SalBitmap* GenPspGraphics::getBitmap( long, long, long, long )
{
SAL_INFO("vcl", "Warning: PrinterGfx::GetBitmap() not implemented");
return nullptr;
}
SalColor GenPspGraphics::getPixel( long, long )
{
OSL_FAIL("Warning: PrinterGfx::GetPixel() not implemented");
return 0;
}
void GenPspGraphics::invert(long,long,long,long,SalInvert)
{
OSL_FAIL("Warning: PrinterGfx::Invert() not implemented");
}
class ImplPspFontData : public PhysicalFontFace
{
private:
sal_IntPtr mnFontId;
public:
explicit ImplPspFontData( const psp::FastPrintFontInfo& );
virtual sal_IntPtr GetFontId() const override { return mnFontId; }
virtual PhysicalFontFace* Clone() const override { return new ImplPspFontData( *this ); }
virtual ImplFontEntry* CreateFontInstance( FontSelectPattern& ) const override;
};
ImplPspFontData::ImplPspFontData( const psp::FastPrintFontInfo& rInfo )
: PhysicalFontFace( GenPspGraphics::Info2FontAttributes(rInfo) ),
mnFontId( rInfo.m_nID )
{}
ImplFontEntry* ImplPspFontData::CreateFontInstance( FontSelectPattern& rFSD ) const
{
ImplServerFontEntry* pEntry = new ImplServerFontEntry( rFSD );
return pEntry;
}
class PspFontLayout : public GenericSalLayout
{
public:
explicit PspFontLayout( ::psp::PrinterGfx& );
virtual bool LayoutText( ImplLayoutArgs& ) override;
virtual void InitFont() const override;
virtual void DrawText( SalGraphics& ) const override;
private:
::psp::PrinterGfx& mrPrinterGfx;
sal_IntPtr mnFontID;
int mnFontHeight;
int mnFontWidth;
bool mbVertical;
bool mbArtItalic;
bool mbArtBold;
};
PspFontLayout::PspFontLayout( ::psp::PrinterGfx& rGfx )
: mrPrinterGfx( rGfx )
{
mnFontID = mrPrinterGfx.GetFontID();
mnFontHeight = mrPrinterGfx.GetFontHeight();
mnFontWidth = mrPrinterGfx.GetFontWidth();
mbVertical = mrPrinterGfx.GetFontVertical();
mbArtItalic = mrPrinterGfx.GetArtificialItalic();
mbArtBold = mrPrinterGfx.GetArtificialBold();
}
bool PspFontLayout::LayoutText( ImplLayoutArgs& rArgs )
{
mbVertical = bool(rArgs.mnFlags & SalLayoutFlags::Vertical);
long nUnitsPerPixel = 1;
sal_GlyphId aOldGlyphId( GF_DROPPED);
long nGlyphWidth = 0;
int nCharPos = -1;
Point aNewPos( 0, 0 );
GlyphItem aPrevItem;
rtl_TextEncoding aFontEnc = mrPrinterGfx.GetFontMgr().getFontEncoding( mnFontID );
const int nLength = rArgs.mrStr.getLength();
const sal_Unicode *pStr = rArgs.mrStr.getStr();
Reserve(nLength);
for(;;)
{
bool bRightToLeft;
if( !rArgs.GetNextPos( &nCharPos, &bRightToLeft ) )
break;
sal_Unicode cChar = pStr[ nCharPos ];
if( bRightToLeft )
cChar = GetMirroredChar( cChar );
// symbol font aliasing: 0x0020-0x00ff -> 0xf020 -> 0xf0ff
if( aFontEnc == RTL_TEXTENCODING_SYMBOL )
if( cChar < 256 )
cChar += 0xf000;
sal_GlyphId aGlyphId( cChar); // printer glyphs = unicode
// update fallback_runs if needed
psp::CharacterMetric aMetric;
// coverity[callee_ptr_arith]
mrPrinterGfx.GetFontMgr().getMetrics( mnFontID, cChar, cChar, &aMetric, mbVertical );
if( aMetric.width == -1 && aMetric.height == -1 )
rArgs.NeedFallback( nCharPos, bRightToLeft );
// finish previous glyph
if( aOldGlyphId != GF_DROPPED )
AppendGlyph( aPrevItem );
aOldGlyphId = aGlyphId;
aNewPos.X() += nGlyphWidth;
// prepare GlyphItem for appending it in next round
nUnitsPerPixel = mrPrinterGfx.GetCharWidth( cChar, cChar, &nGlyphWidth );
int nGlyphFlags = bRightToLeft ? GlyphItem::IS_RTL_GLYPH : 0;
aGlyphId |= GF_ISCHAR;
aPrevItem = GlyphItem( nCharPos, aGlyphId, aNewPos, nGlyphFlags, nGlyphWidth );
}
// append last glyph item if any
if( aOldGlyphId != GF_DROPPED )
AppendGlyph( aPrevItem );
SetOrientation( mrPrinterGfx.GetFontAngle() );
SetUnitsPerPixel( nUnitsPerPixel );
return (aOldGlyphId != GF_DROPPED);
}
class PspServerFontLayout : public ServerFontLayout
{
public:
PspServerFontLayout( psp::PrinterGfx&, ServerFont& rFont, const ImplLayoutArgs& rArgs );
virtual void InitFont() const override;
const sal_Unicode* getTextPtr() const { return maText.getStr() - mnMinCharPos; }
int getMinCharPos() const { return mnMinCharPos; }
int getMaxCharPos() const { return mnMinCharPos+maText.getLength()-1; }
private:
::psp::PrinterGfx& mrPrinterGfx;
sal_IntPtr mnFontID;
int mnFontHeight;
int mnFontWidth;
bool mbVertical;
bool mbArtItalic;
bool mbArtBold;
OUString maText;
int mnMinCharPos;
};
PspServerFontLayout::PspServerFontLayout( ::psp::PrinterGfx& rGfx, ServerFont& rFont, const ImplLayoutArgs& rArgs )
: ServerFontLayout( rFont ),
mrPrinterGfx( rGfx )
{
mnFontID = mrPrinterGfx.GetFontID();
mnFontHeight = mrPrinterGfx.GetFontHeight();
mnFontWidth = mrPrinterGfx.GetFontWidth();
mbVertical = mrPrinterGfx.GetFontVertical();
mbArtItalic = mrPrinterGfx.GetArtificialItalic();
mbArtBold = mrPrinterGfx.GetArtificialBold();
const sal_Unicode *pStr = rArgs.mrStr.getStr();
maText = OUString( pStr + rArgs.mnMinCharPos, rArgs.mnEndCharPos - rArgs.mnMinCharPos+1 );
mnMinCharPos = rArgs.mnMinCharPos;
}
void PspServerFontLayout::InitFont() const
{
mrPrinterGfx.SetFont( mnFontID, mnFontHeight, mnFontWidth,
mnOrientation, mbVertical, mbArtItalic, mbArtBold );
}
static void DrawPrinterLayout( const SalLayout& rLayout, ::psp::PrinterGfx& rGfx, bool bIsPspServerFontLayout )
{
const int nMaxGlyphs = 200;
sal_GlyphId aGlyphAry[ nMaxGlyphs ];
DeviceCoordinate aWidthAry[ nMaxGlyphs ];
sal_Int32 aIdxAry [ nMaxGlyphs ];
sal_Unicode aUnicodes[ nMaxGlyphs ];
int aCharPosAry [ nMaxGlyphs ];
Point aPos;
long nUnitsPerPixel = rLayout.GetUnitsPerPixel();
const sal_Unicode* pText = nullptr;
int nMinCharPos = 0;
int nMaxCharPos = 0;
if (bIsPspServerFontLayout)
{
const PspServerFontLayout * pPspLayout = dynamic_cast<const PspServerFontLayout*>(&rLayout);
#if ENABLE_GRAPHITE
const GraphiteServerFontLayout * pGrLayout = dynamic_cast<const GraphiteServerFontLayout*>(&rLayout);
#endif
if (pPspLayout)
{
pText = pPspLayout->getTextPtr();
nMinCharPos = pPspLayout->getMinCharPos();
nMaxCharPos = pPspLayout->getMaxCharPos();
}
#if ENABLE_GRAPHITE
else if (pGrLayout)
{
}
#endif
}
for( int nStart = 0;; )
{
int nGlyphCount = rLayout.GetNextGlyphs( nMaxGlyphs, aGlyphAry, aPos, nStart, aWidthAry, pText ? aCharPosAry : nullptr );
if( !nGlyphCount )
break;
DeviceCoordinate nXOffset = 0;
for( int i = 0; i < nGlyphCount; ++i )
{
nXOffset += aWidthAry[ i ];
aIdxAry[ i ] = nXOffset / nUnitsPerPixel;
sal_GlyphId aGlyphId = aGlyphAry[i] & (GF_IDXMASK | GF_ROTMASK);
if( pText )
aUnicodes[i] = (aCharPosAry[i] >= nMinCharPos && aCharPosAry[i] <= nMaxCharPos) ? pText[ aCharPosAry[i] ] : 0;
else
aUnicodes[i] = (aGlyphAry[i] & GF_ISCHAR) ? aGlyphId : 0;
aGlyphAry[i] = aGlyphId;
}
rGfx.DrawGlyphs( aPos, aGlyphAry, aUnicodes, nGlyphCount, aIdxAry );
}
}
void PspFontLayout::InitFont() const
{
mrPrinterGfx.SetFont( mnFontID, mnFontHeight, mnFontWidth,
mnOrientation, mbVertical, mbArtItalic, mbArtBold );
}
void PspFontLayout::DrawText( SalGraphics& ) const
{
DrawPrinterLayout( *this, mrPrinterGfx, false );
}
void GenPspGraphics::DrawServerFontLayout( const ServerFontLayout& rLayout )
{
// print complex text
DrawPrinterLayout( rLayout, *m_pPrinterGfx, true );
}
const FontCharMapPtr GenPspGraphics::GetFontCharMap() const
{
if( !m_pServerFont[0] )
return nullptr;
const FontCharMapPtr pFCMap = m_pServerFont[0]->GetFontCharMap();
return pFCMap;
}
bool GenPspGraphics::GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const
{
if (!m_pServerFont[0])
return false;
return m_pServerFont[0]->GetFontCapabilities(rFontCapabilities);
}
sal_uInt16 GenPspGraphics::SetFont( FontSelectPattern *pEntry, int nFallbackLevel )
{
// release all fonts that are to be overridden
for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i )
{
if( m_pServerFont[i] != nullptr )
{
// old server side font is no longer referenced
GlyphCache::GetInstance().UncacheFont( *m_pServerFont[i] );
m_pServerFont[i] = nullptr;
}
}
// return early if there is no new font
if( !pEntry )
return 0;
sal_IntPtr nID = pEntry->mpFontData ? pEntry->mpFontData->GetFontId() : 0;
// determine which font attributes need to be emulated
bool bArtItalic = false;
bool bArtBold = false;
if( pEntry->GetSlantType() == ITALIC_OBLIQUE || pEntry->GetSlantType() == ITALIC_NORMAL )
{
FontItalic eItalic = m_pPrinterGfx->GetFontMgr().getFontItalic( nID );
if( eItalic != ITALIC_NORMAL && eItalic != ITALIC_OBLIQUE )
bArtItalic = true;
}
int nWeight = (int)pEntry->GetWeight();
int nRealWeight = (int)m_pPrinterGfx->GetFontMgr().getFontWeight( nID );
if( nRealWeight <= (int)WEIGHT_MEDIUM && nWeight > (int)WEIGHT_MEDIUM )
{
bArtBold = true;
}
// also set the serverside font for layouting
m_bFontVertical = pEntry->mbVertical;
if( pEntry->mpFontData )
{
// requesting a font provided by builtin rasterizer
ServerFont* pServerFont = GlyphCache::GetInstance().CacheFont( *pEntry );
if( pServerFont != nullptr )
{
if( pServerFont->TestFont() )
m_pServerFont[ nFallbackLevel ] = pServerFont;
else
GlyphCache::GetInstance().UncacheFont( *pServerFont );
}
}
// set the printer font
return m_pPrinterGfx->SetFont( nID,
pEntry->mnHeight,
pEntry->mnWidth,
pEntry->mnOrientation,
pEntry->mbVertical,
bArtItalic,
bArtBold
);
}
void GenPspGraphics::SetTextColor( SalColor nSalColor )
{
psp::PrinterColor aColor (SALCOLOR_RED (nSalColor),
SALCOLOR_GREEN (nSalColor),
SALCOLOR_BLUE (nSalColor));
m_pPrinterGfx->SetTextColor (aColor);
}
bool GenPspGraphics::AddTempDevFont( PhysicalFontCollection*, const OUString&,const OUString& )
{
return false;
}
bool GenPspGraphics::AddTempDevFontHelper( PhysicalFontCollection* pFontCollection,
const OUString& rFileURL,
const OUString& rFontName,
GlyphCache &rGC )
{
// inform PSP font manager
OUString aUSystemPath;
OSL_VERIFY( !osl::FileBase::getSystemPathFromFileURL( rFileURL, aUSystemPath ) );
rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
OString aOFileName( OUStringToOString( aUSystemPath, aEncoding ) );
psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
std::vector<psp::fontID> aFontIds = rMgr.addFontFile( aOFileName );
if( aFontIds.empty() )
return false;
for (std::vector<psp::fontID>::iterator aI = aFontIds.begin(), aEnd = aFontIds.end(); aI != aEnd; ++aI)
{
// prepare font data
psp::FastPrintFontInfo aInfo;
rMgr.getFontFastInfo( *aI, aInfo );
aInfo.m_aFamilyName = rFontName;
// inform glyph cache of new font
ImplFontAttributes aDFA = GenPspGraphics::Info2FontAttributes( aInfo );
aDFA.IncreaseQualityBy( 5800 );
int nFaceNum = rMgr.getFontFaceNumber( aInfo.m_nID );
const OString& rFileName = rMgr.getFontFileSysPath( aInfo.m_nID );
rGC.AddFontFile( rFileName, nFaceNum, aInfo.m_nID, aDFA );
}
// announce new font to device's font list
rGC.AnnounceFonts( pFontCollection );
return true;
}
void GenPspGraphics::GetDevFontList( PhysicalFontCollection *pFontCollection )
{
::std::list< psp::fontID > aList;
psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
rMgr.getFontList( aList );
::std::list< psp::fontID >::iterator it;
psp::FastPrintFontInfo aInfo;
for (it = aList.begin(); it != aList.end(); ++it)
if (rMgr.getFontFastInfo (*it, aInfo))
AnnounceFonts( pFontCollection, aInfo );
// register platform specific font substitutions if available
SalGenericInstance::RegisterFontSubstitutors( pFontCollection );
}
void GenPspGraphics::ClearDevFontCache()
{
GlyphCache::GetInstance().ClearFontCache();
}
void GenPspGraphics::GetFontAttributes( ImplFontAttributes *pFontAttributes, int )
{
const psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
psp::PrintFontInfo aInfo;
if (rMgr.getFontInfo (m_pPrinterGfx->GetFontID(), aInfo))
{
ImplFontAttributes aDFA = Info2FontAttributes( aInfo );
static_cast<ImplFontAttributes&>(*pFontAttributes) = aDFA;
pFontAttributes->SetBuiltInFontFlag( aDFA.IsBuiltInFont() );
pFontAttributes->SetScalableFlag( true );
pFontAttributes->SetTrueTypeFlag( false ); // FIXME, needed?
pFontAttributes->SetOrientation( m_pPrinterGfx->GetFontAngle() );
pFontAttributes->SetSlant( 0 );
sal_Int32 nTextHeight = m_pPrinterGfx->GetFontHeight();
sal_Int32 nTextWidth = m_pPrinterGfx->GetFontWidth();
if( ! nTextWidth )
nTextWidth = nTextHeight;
pFontAttributes->SetWidth( nTextWidth );
pFontAttributes->SetAscent( ( aInfo.m_nAscend * nTextHeight + 500 ) / 1000 );
pFontAttributes->SetDescent( ( aInfo.m_nDescend * nTextHeight + 500 ) / 1000 );
pFontAttributes->SetInternalLeading( ( aInfo.m_nLeading * nTextHeight + 500 ) / 1000 );
pFontAttributes->SetExternalLeading( 0 );
}
}
bool GenPspGraphics::GetGlyphBoundRect( sal_GlyphId aGlyphId, Rectangle& rRect )
{
const int nLevel = aGlyphId >> GF_FONTSHIFT;
if( nLevel >= MAX_FALLBACK )
return false;
ServerFont* pSF = m_pServerFont[ nLevel ];
if( !pSF )
return false;
aGlyphId &= GF_IDXMASK;
const GlyphMetric& rGM = pSF->GetGlyphMetric( aGlyphId );
rRect = Rectangle( rGM.GetOffset(), rGM.GetSize() );
return true;
}
bool GenPspGraphics::GetGlyphOutline( sal_GlyphId aGlyphId,
basegfx::B2DPolyPolygon& rB2DPolyPoly )
{
const int nLevel = aGlyphId >> GF_FONTSHIFT;
if( nLevel >= MAX_FALLBACK )
return false;
ServerFont* pSF = m_pServerFont[ nLevel ];
if( !pSF )
return false;
aGlyphId &= GF_IDXMASK;
if( pSF->GetGlyphOutline( aGlyphId, rB2DPolyPoly ) )
return true;
return false;
}
SalLayout* GenPspGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLevel )
{
// workaround for printers not handling glyph indexing for non-TT fonts
int nFontId = m_pPrinterGfx->GetFontID();
if( psp::fonttype::TrueType != psp::PrintFontManager::get().getFontType( nFontId ) )
rArgs.mnFlags |= SalLayoutFlags::DisableGlyphProcessing;
else if( nFallbackLevel > 0 )
rArgs.mnFlags &= ~SalLayoutFlags::DisableGlyphProcessing;
GenericSalLayout* pLayout = nullptr;
if( m_pServerFont[ nFallbackLevel ]
&& !(rArgs.mnFlags & SalLayoutFlags::DisableGlyphProcessing) )
{
#if ENABLE_GRAPHITE
// Is this a Graphite font?
if (GraphiteServerFontLayout::IsGraphiteEnabledFont(*m_pServerFont[nFallbackLevel]))
{
pLayout = new GraphiteServerFontLayout(*m_pServerFont[nFallbackLevel]);
}
else
#endif
pLayout = new PspServerFontLayout( *m_pPrinterGfx, *m_pServerFont[nFallbackLevel], rArgs );
}
else
pLayout = new PspFontLayout( *m_pPrinterGfx );
return pLayout;
}
bool GenPspGraphics::CreateFontSubset(
const OUString& rToFile,
const PhysicalFontFace* pFont,
const sal_GlyphId* pGlyphIds,
const sal_uInt8* pEncoding,
sal_Int32* pWidths,
int nGlyphCount,
FontSubsetInfo& rInfo
)
{
// in this context the pFont->GetFontId() is a valid PSP
// font since they are the only ones left after the PDF
// export has filtered its list of subsettable fonts (for
// which this method was created). The correct way would
// be to have the GlyphCache search for the PhysicalFontFace pFont
psp::fontID aFont = pFont->GetFontId();
psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
bool bSuccess = rMgr.createFontSubset( rInfo,
aFont,
rToFile,
pGlyphIds,
pEncoding,
pWidths,
nGlyphCount );
return bSuccess;
}
const Ucs2SIntMap* GenPspGraphics::GetFontEncodingVector( const PhysicalFontFace* pFont, const Ucs2OStrMap** pNonEncoded, std::set<sal_Unicode> const** ppPriority)
{
// in this context the pFont->GetFontId() is a valid PSP
// font since they are the only ones left after the PDF
// export has filtered its list of subsettable fonts (for
// which this method was created). The correct way would
// be to have the GlyphCache search for the PhysicalFontFace pFont
psp::fontID aFont = pFont->GetFontId();
return GenPspGraphics::DoGetFontEncodingVector( aFont, pNonEncoded, ppPriority );
}
void GenPspGraphics::GetGlyphWidths( const PhysicalFontFace* pFont,
bool bVertical,
Int32Vector& rWidths,
Ucs2UIntMap& rUnicodeEnc )
{
// in this context the pFont->GetFontId() is a valid PSP
// font since they are the only ones left after the PDF
// export has filtered its list of subsettable fonts (for
// which this method was created). The correct way would
// be to have the GlyphCache search for the PhysicalFontFace pFont
psp::fontID aFont = pFont->GetFontId();
GenPspGraphics::DoGetGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc );
}
const Ucs2SIntMap* GenPspGraphics::DoGetFontEncodingVector( fontID aFont, const Ucs2OStrMap** pNonEncoded, std::set<sal_Unicode> const** ppPriority)
{
psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
psp::PrintFontInfo aFontInfo;
if( ! rMgr.getFontInfo( aFont, aFontInfo ) )
{
if( pNonEncoded )
*pNonEncoded = nullptr;
return nullptr;
}
return rMgr.getEncodingMap( aFont, pNonEncoded, ppPriority );
}
void GenPspGraphics::DoGetGlyphWidths( psp::fontID aFont,
bool bVertical,
Int32Vector& rWidths,
Ucs2UIntMap& rUnicodeEnc )
{
psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
rMgr.getGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc );
}
ImplFontAttributes GenPspGraphics::Info2FontAttributes( const psp::FastPrintFontInfo& rInfo )
{
ImplFontAttributes aDFA;
aDFA.SetFamilyName( rInfo.m_aFamilyName );
aDFA.SetStyleName( rInfo.m_aStyleName );
aDFA.SetFamilyType( rInfo.m_eFamilyStyle );
aDFA.SetWeight( rInfo.m_eWeight );
aDFA.SetItalic( rInfo.m_eItalic );
aDFA.SetWidthType( rInfo.m_eWidth );
aDFA.SetPitch( rInfo.m_ePitch );
aDFA.SetSymbolFlag( (rInfo.m_aEncoding == RTL_TEXTENCODING_SYMBOL) );
aDFA.SetSubsettableFlag( rInfo.m_bSubsettable );
aDFA.SetEmbeddableFlag( rInfo.m_bEmbeddable );
switch( rInfo.m_eType )
{
case psp::fonttype::TrueType:
aDFA.SetQuality( 512 );
aDFA.SetBuiltInFontFlag( false );
break;
case psp::fonttype::Type1:
aDFA.SetQuality( 0 );
aDFA.SetBuiltInFontFlag( false );
break;
default:
aDFA.SetQuality( 0 );
aDFA.SetBuiltInFontFlag( false );
break;
}
aDFA.SetOrientationFlag( true );
// add font family name aliases
::std::list< OUString >::const_iterator it = rInfo.m_aAliases.begin();
for(; it != rInfo.m_aAliases.end(); ++it )
aDFA.AddMapName( *it );
#if OSL_DEBUG_LEVEL > 2
if( aDFA.HasMapNames() )
{
OString aOrigName(OUStringToOString(aDFA.GetFamilyName(), osl_getThreadTextEncoding()));
OString aAliasNames(OUStringToOString(aDFA.GetAliasNames(), osl_getThreadTextEncoding()));
SAL_INFO( "vcl.fonts", "using alias names " << aAliasNames.getStr() << " for font family " << aOrigName.getStr() );
}
#endif
return aDFA;
}
namespace vcl
{
const char* getLangBoost()
{
const char* pLangBoost;
const LanguageType eLang = Application::GetSettings().GetUILanguageTag().getLanguageType();
if (eLang == LANGUAGE_JAPANESE)
pLangBoost = "jan";
else if (MsLangId::isKorean(eLang))
pLangBoost = "kor";
else if (MsLangId::isSimplifiedChinese(eLang))
pLangBoost = "zhs";
else if (MsLangId::isTraditionalChinese(eLang))
pLangBoost = "zht";
else
pLangBoost = nullptr;
return pLangBoost;
}
}
void GenPspGraphics::AnnounceFonts( PhysicalFontCollection* pFontCollection, const psp::FastPrintFontInfo& aInfo )
{
int nQuality = 0;
if( aInfo.m_eType == psp::fonttype::TrueType )
{
// asian type 1 fonts are not known
psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
OString aFileName( rMgr.getFontFileSysPath( aInfo.m_nID ) );
int nPos = aFileName.lastIndexOf( '_' );
if( nPos == -1 || aFileName[nPos+1] == '.' )
nQuality += 5;
else
{
static const char* pLangBoost = nullptr;
static bool bOnce = true;
if( bOnce )
{
bOnce = false;
pLangBoost = vcl::getLangBoost();
}
if( pLangBoost )
if( aFileName.copy( nPos+1, 3 ).equalsIgnoreAsciiCase( pLangBoost ) )
nQuality += 10;
}
}
ImplPspFontData* pFD = new ImplPspFontData( aInfo );
pFD->IncreaseQualityBy( nQuality );
pFontCollection->Add( pFD );
}
bool GenPspGraphics::blendBitmap( const SalTwoRect&, const SalBitmap& )
{
return false;
}
bool GenPspGraphics::blendAlphaBitmap( const SalTwoRect&, const SalBitmap&, const SalBitmap&, const SalBitmap& )
{
return false;
}
bool GenPspGraphics::drawAlphaBitmap( const SalTwoRect&,
const SalBitmap&,
const SalBitmap& )
{
return false;
}
bool GenPspGraphics::drawTransformedBitmap(
const basegfx::B2DPoint& rNull,
const basegfx::B2DPoint& rX,
const basegfx::B2DPoint& rY,
const SalBitmap& rSourceBitmap,
const SalBitmap* pAlphaBitmap)
{
// here direct support for transformed bitmaps can be implemented
(void)rNull; (void)rX; (void)rY; (void)rSourceBitmap; (void)pAlphaBitmap;
return false;
}
bool GenPspGraphics::drawAlphaRect( long, long, long, long, sal_uInt8 )
{
return false;
}
SystemGraphicsData GenPspGraphics::GetGraphicsData() const
{
return SystemGraphicsData();
}
#if ENABLE_CAIRO_CANVAS
bool GenPspGraphics::SupportsCairo() const
{
return false;
}
cairo::SurfaceSharedPtr GenPspGraphics::CreateSurface(const cairo::CairoSurfaceSharedPtr& /*rSurface*/) const
{
return cairo::SurfaceSharedPtr();
}
cairo::SurfaceSharedPtr GenPspGraphics::CreateSurface(const OutputDevice& /*rRefDevice*/, int /*x*/, int /*y*/, int /*width*/, int /*height*/) const
{
return cairo::SurfaceSharedPtr();
}
cairo::SurfaceSharedPtr GenPspGraphics::CreateBitmapSurface(const OutputDevice& /*rRefDevice*/, const BitmapSystemData& /*rData*/, const Size& /*rSize*/) const
{
return cairo::SurfaceSharedPtr();
}
css::uno::Any GenPspGraphics::GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& /*rSurface*/, const basegfx::B2ISize& /*rSize*/) const
{
return css::uno::Any();
}
SystemFontData GenPspGraphics::GetSysFontData( int /* nFallbacklevel */ ) const
{
return SystemFontData();
}
#endif // ENABLE_CAIRO_CANVAS
bool GenPspGraphics::supportsOperation( OutDevSupportType ) const
{
return false;
}
void GenPspGraphics::DoFreeEmbedFontData( const void* pData, long nLen )
{
#if defined( UNX )
if( pData )
munmap( const_cast<void *>(pData), nLen );
#else
(void)nLen;
rtl_freeMemory( (void *)pData );
#endif
}
const void* GenPspGraphics::DoGetEmbedFontData( psp::fontID aFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, size_t nLen, FontSubsetInfo& rInfo, long* pDataLen )
{
psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
psp::PrintFontInfo aFontInfo;
if( ! rMgr.getFontInfo( aFont, aFontInfo ) )
return nullptr;
// fill in font info
rInfo.m_nAscent = aFontInfo.m_nAscend;
rInfo.m_nDescent = aFontInfo.m_nDescend;
rInfo.m_aPSName = rMgr.getPSName( aFont );
int xMin, yMin, xMax, yMax;
rMgr.getFontBoundingBox( aFont, xMin, yMin, xMax, yMax );
std::vector<psp::CharacterMetric> aMetrics(nLen);
sal_Ucs aUnicodes[nLen];
if( aFontInfo.m_aEncoding == RTL_TEXTENCODING_SYMBOL && aFontInfo.m_eType == psp::fonttype::Type1 )
{
for (size_t i = 0; i < nLen; ++i)
aUnicodes[i] = pUnicodes[i] < 0x0100 ? pUnicodes[i] + 0xf000 : pUnicodes[i];
pUnicodes = aUnicodes;
}
if (!rMgr.getMetrics(aFont, pUnicodes, nLen, aMetrics.data()))
return nullptr;
OString aSysPath = rMgr.getFontFileSysPath( aFont );
#if defined( UNX )
int fd = open( aSysPath.getStr(), O_RDONLY );
if( fd < 0 )
return nullptr;
struct stat aStat;
if( fstat( fd, &aStat ) )
{
close( fd );
return nullptr;
}
void* pFile = mmap( nullptr, aStat.st_size, PROT_READ, MAP_SHARED, fd, 0 );
close( fd );
if( pFile == MAP_FAILED )
return nullptr;
*pDataLen = aStat.st_size;
#else
// FIXME: test me ! ...
OUString aURL;
if( osl::File::getFileURLFromSystemPath( OStringToOUString( aSysPath, osl_getThreadTextEncoding() ), aURL ) != osl::File::E_None )
return NULL;
osl::File aFile( aURL );
if( aFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_NoLock ) != osl::File::E_None )
return NULL;
osl::DirectoryItem aItem;
osl::DirectoryItem::get( aURL, aItem );
osl::FileStatus aFileStatus( osl_FileStatus_Mask_FileSize );
aItem.getFileStatus( aFileStatus );
void *pFile = rtl_allocateMemory( aFileStatus.getFileSize() );
sal_uInt64 nRead = 0;
aFile.read( pFile, aFileStatus.getFileSize(), nRead );
*pDataLen = (long) nRead;
#endif
rInfo.m_aFontBBox = Rectangle( Point( xMin, yMin ), Size( xMax-xMin, yMax-yMin ) );
rInfo.m_nCapHeight = yMax; // Well ...
for (size_t i = 0; i < nLen; ++i)
pWidths[i] = (aMetrics[i].width > 0 ? aMetrics[i].width : 0);
switch( aFontInfo.m_eType )
{
case psp::fonttype::TrueType:
rInfo.m_nFontType = FontSubsetInfo::SFNT_TTF;
break;
case psp::fonttype::Type1: {
const bool bPFA = *static_cast<unsigned char*>(pFile) < 0x80;
rInfo.m_nFontType = bPFA ? FontSubsetInfo::TYPE1_PFA : FontSubsetInfo::TYPE1_PFB;
}
break;
default:
DoFreeEmbedFontData( pFile, *pDataLen );
return nullptr;
}
return pFile;
}
void GenPspGraphics::FreeEmbedFontData( const void* pData, long nLen )
{
DoFreeEmbedFontData( pData, nLen );
}
const void* GenPspGraphics::GetEmbedFontData( const PhysicalFontFace* pFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, size_t nLen, FontSubsetInfo& rInfo, long* pDataLen )
{
// in this context the pFont->GetFontId() is a valid PSP
// font since they are the only ones left after the PDF
// export has filtered its list of subsettable fonts (for
// which this method was created). The correct way would
// be to have the GlyphCache search for the PhysicalFontFace pFont
psp::fontID aFont = pFont->GetFontId();
return DoGetEmbedFontData(aFont, pUnicodes, pWidths, nLen, rInfo, pDataLen);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|