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
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
|
/* -*- 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 <sfx2/dialoghelper.hxx>
#include <sfx2/viewsh.hxx>
#include <sfx2/printer.hxx>
#include <vcl/builderfactory.hxx>
#include <vcl/metric.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <unicode/uchar.h>
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/i18n/BreakIterator.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/i18n/ScriptType.hpp>
#include <vector>
#include <deque>
#include <svtools/colorcfg.hxx>
#include <svtools/sampletext.hxx>
#include <svx/fntctrl.hxx>
#include <svx/dialogs.hrc>
#include <svx/sdasitm.hxx>
// Item set includes
#include <svl/itemset.hxx>
#include <svl/itempool.hxx>
#include <svl/stritem.hxx>
#include <svl/languageoptions.hxx>
#include <editeng/colritem.hxx>
#include <editeng/fontitem.hxx>
#include <editeng/editids.hrc>
#include <editeng/postitem.hxx>
#include <editeng/udlnitem.hxx>
#include <editeng/crossedoutitem.hxx>
#include <editeng/contouritem.hxx>
#include <editeng/wghtitem.hxx>
#include <editeng/fhgtitem.hxx>
#include <editeng/shdditem.hxx>
#include <editeng/escapementitem.hxx>
#include <editeng/wrlmitem.hxx>
#include <editeng/cmapitem.hxx>
#include <editeng/kernitem.hxx>
#include <editeng/brushitem.hxx>
#include <editeng/emphasismarkitem.hxx>
#include <editeng/charreliefitem.hxx>
#include <editeng/twolinesitem.hxx>
#include <editeng/charscaleitem.hxx>
#include <editeng/langitem.hxx>
//TODO: remove this and calculate off the actual size of text, not
//an arbitrary number of characters
#define TEXT_WIDTH 80
#define ISITEMSET rSet.GetItemState(nWhich)>=SfxItemState::DEFAULT
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using ::com::sun::star::i18n::XBreakIterator;
using ::com::sun::star::i18n::BreakIterator;
// small helper functions to set fonts
namespace
{
void scaleFontWidth(vcl::Font& rFont, vcl::RenderContext& rRenderContext,long& n100PercentFont)
{
rFont.SetAverageFontWidth(0);
n100PercentFont = rRenderContext.GetFontMetric(rFont).GetAverageFontWidth();
}
void initFont(vcl::Font& rFont)
{
rFont.SetTransparent(true);
rFont.SetAlignment(ALIGN_BASELINE);
}
void setFontSize(vcl::Font& rFont)
{
Size aSize(rFont.GetFontSize());
aSize.Height() = (aSize.Height() * 3) / 5;
aSize.Width() = (aSize.Width() * 3) / 5;
rFont.SetFontSize(aSize);
}
void calcFontHeightAnyAscent(vcl::RenderContext& rRenderContext, const vcl::Font& rFont, long& nHeight, long& nAscent)
{
if (!nHeight)
{
rRenderContext.SetFont(rFont);
FontMetric aMetric(rRenderContext.GetFontMetric());
nHeight = aMetric.GetLineHeight();
nAscent = aMetric.GetAscent();
}
}
void setFont(const SvxFont& rNewFont, SvxFont& rImplFont)
{
rImplFont = rNewFont;
rImplFont.SetTransparent(true);
rImplFont.SetAlignment(ALIGN_BASELINE);
}
} // end anonymous namespace
class FontPrevWin_Impl
{
friend class SvxFontPrevWindow;
SvxFont maFont;
VclPtr<Printer> mpPrinter;
bool mbDelPrinter;
Reference <XBreakIterator> mxBreak;
std::vector<sal_uIntPtr> maTextWidth;
std::deque<sal_Int32> maScriptChg;
std::vector<sal_uInt16> maScriptType;
SvxFont maCJKFont;
SvxFont maCTLFont;
OUString maText;
OUString maScriptText;
Color* mpColor;
Color* mpBackColor;
long mnAscent;
sal_Unicode mcStartBracket;
sal_Unicode mcEndBracket;
long mn100PercentFontWidth; // initial -1 -> not set yet
long mn100PercentFontWidthCJK;
long mn100PercentFontWidthCTL;
sal_uInt16 mnFontWidthScale;
bool mbSelection : 1;
bool mbGetSelection : 1;
bool mbUseResText : 1;
bool mbTwoLines : 1;
bool mbUseFontNameAsText : 1;
bool mbTextInited : 1;
bool m_bCJKEnabled;
bool m_bCTLEnabled;
public:
FontPrevWin_Impl() :
mpPrinter(nullptr),
mbDelPrinter(false),
mpColor(nullptr),
mpBackColor(nullptr),
mnAscent(0),
mcStartBracket(0),
mcEndBracket(0),
mnFontWidthScale(100),
mbSelection(false),
mbGetSelection(false),
mbUseResText(false),
mbTwoLines(false),
mbUseFontNameAsText(false),
mbTextInited(false)
{
SvtLanguageOptions aLanguageOptions;
m_bCJKEnabled = aLanguageOptions.IsAnyEnabled();
m_bCTLEnabled = aLanguageOptions.IsCTLFontEnabled();
Invalidate100PercentFontWidth();
}
~FontPrevWin_Impl()
{
delete mpColor;
delete mpBackColor;
if (mbDelPrinter)
mpPrinter.disposeAndClear();
}
void CheckScript();
Size CalcTextSize(vcl::RenderContext& rRenderContext, OutputDevice* pPrinter, const SvxFont& rFont);
void DrawPrev(vcl::RenderContext& rRenderContext, Printer* pPrinter, Point& rPt, const SvxFont& rFont);
bool SetFontWidthScale(sal_uInt16 nScaleInPercent);
inline void Invalidate100PercentFontWidth();
inline bool Is100PercentFontWidthValid() const;
void ScaleFontWidth(vcl::RenderContext& rRenderContext);
// scales rNonCJKFont and aCJKFont depending on nFontWidthScale and
// sets the 100%-Font-Widths
};
inline void FontPrevWin_Impl::Invalidate100PercentFontWidth()
{
mn100PercentFontWidth = mn100PercentFontWidthCJK = mn100PercentFontWidthCTL = -1;
}
inline bool FontPrevWin_Impl::Is100PercentFontWidthValid() const
{
DBG_ASSERT( ( mn100PercentFontWidth == -1 && mn100PercentFontWidthCJK == -1 ) ||
( mn100PercentFontWidth != -1 && mn100PercentFontWidthCJK != -1 ) ||
( mn100PercentFontWidth == -1 && mn100PercentFontWidthCTL == -1 ) ||
( mn100PercentFontWidth != -1 && mn100PercentFontWidthCTL != -1 ),
"*FontPrevWin_Impl::Is100PercentFontWidthValid(): 100PercentFontWidth's not synchronous" );
return mn100PercentFontWidth != -1;
}
/*
* evalutates the scripttypes of the actual string.
* Afterwards the positions of script change are notified in aScriptChg,
* the scripttypes in aScriptType.
* The aTextWidth array will be filled with zero.
*/
void FontPrevWin_Impl::CheckScript()
{
assert(!maText.isEmpty()); // must have a preview text here!
if (maText == maScriptText)
{
return; // already initialized
}
maScriptText = maText;
maScriptChg.clear();
maScriptType.clear();
maTextWidth.clear();
if (!mxBreak.is())
{
Reference<XComponentContext> xContext = ::comphelper::getProcessComponentContext();
mxBreak = BreakIterator::create(xContext);
}
sal_uInt16 nScript = 0;
sal_Int32 nChg = 0;
while (nChg < maText.getLength())
{
nScript = mxBreak->getScriptType(maText, nChg);
nChg = mxBreak->endOfScript(maText, nChg, nScript);
if (nChg < maText.getLength() && nChg > 0 &&
(css::i18n::ScriptType::WEAK ==
mxBreak->getScriptType(maText, nChg - 1)))
{
int8_t nType = u_charType(maText[nChg]);
if (nType == U_NON_SPACING_MARK || nType == U_ENCLOSING_MARK ||
nType == U_COMBINING_SPACING_MARK)
{
maScriptChg.push_back(nChg - 1);
}
else
{
maScriptChg.push_back(nChg);
}
}
else
{
maScriptChg.push_back(nChg);
}
maScriptType.push_back(nScript);
maTextWidth.push_back(0);
}
}
/*
* Size FontPrevWin_Impl::CalcTextSize(..)
* fills the aTextWidth array with the text width of every part
* of the actual string without a script change inside.
* For Latin parts the given rFont will be used,
* for Asian parts the aCJKFont.
* The returned size contains the whole string.
* The member nAscent is calculated to the maximal ascent of all used fonts.
*/
Size FontPrevWin_Impl::CalcTextSize(vcl::RenderContext& rRenderContext, OutputDevice* _pPrinter, const SvxFont& rInFont)
{
sal_uInt16 nScript;
sal_uInt16 nIdx = 0;
sal_Int32 nStart = 0;
sal_Int32 nEnd;
size_t nCnt = maScriptChg.size();
if (nCnt)
{
nEnd = maScriptChg[nIdx];
nScript = maScriptType[nIdx];
}
else
{
nEnd = maText.getLength();
nScript = css::i18n::ScriptType::LATIN;
}
long nTxtWidth = 0;
long nCJKHeight = 0;
long nCTLHeight = 0;
long nHeight = 0;
mnAscent = 0;
long nCJKAscent = 0;
long nCTLAscent = 0;
do
{
const SvxFont& rFont = (nScript == css::i18n::ScriptType::ASIAN) ?
maCJKFont :
((nScript == css::i18n::ScriptType::COMPLEX) ?
maCTLFont :
rInFont);
sal_uIntPtr nWidth = rFont.GetTextSize(_pPrinter, maText, nStart, nEnd - nStart).Width();
if (nIdx >= maTextWidth.size())
break;
maTextWidth[nIdx++] = nWidth;
nTxtWidth += nWidth;
switch (nScript)
{
case css::i18n::ScriptType::ASIAN:
calcFontHeightAnyAscent(rRenderContext, maCJKFont, nCJKHeight, nCJKAscent);
break;
case css::i18n::ScriptType::COMPLEX:
calcFontHeightAnyAscent(rRenderContext, maCTLFont, nCTLHeight, nCTLAscent);
break;
default:
calcFontHeightAnyAscent(rRenderContext, rFont, nHeight, mnAscent);
}
if (nEnd < maText.getLength() && nIdx < nCnt)
{
nStart = nEnd;
nEnd = maScriptChg[nIdx];
nScript = maScriptType[nIdx];
}
else
break;
}
while(true);
nHeight -= mnAscent;
nCJKHeight -= nCJKAscent;
nCTLHeight -= nCTLAscent;
if (nHeight < nCJKHeight)
nHeight = nCJKHeight;
if (mnAscent < nCJKAscent)
mnAscent = nCJKAscent;
if (nHeight < nCTLHeight)
nHeight = nCTLHeight;
if (mnAscent < nCTLAscent)
mnAscent = nCTLAscent;
nHeight += mnAscent;
Size aTxtSize(nTxtWidth, nHeight);
return aTxtSize;
}
/*
* void FontPrevWin_Impl::DrawPrev(..)
* calls SvxFont::DrawPrev(..) for every part of the string without a script
* change inside, for Asian parts the aCJKFont will be used, otherwise the
* given rFont.
*/
void FontPrevWin_Impl::DrawPrev(vcl::RenderContext& rRenderContext, Printer* _pPrinter, Point &rPt, const SvxFont& rInFont)
{
vcl::Font aOldFont = _pPrinter->GetFont();
sal_uInt16 nScript;
sal_uInt16 nIdx = 0;
sal_Int32 nStart = 0;
sal_Int32 nEnd;
size_t nCnt = maScriptChg.size();
if (nCnt)
{
nEnd = maScriptChg[nIdx];
nScript = maScriptType[nIdx];
}
else
{
nEnd = maText.getLength();
nScript = css::i18n::ScriptType::LATIN;
}
do
{
const SvxFont& rFont = (nScript == css::i18n::ScriptType::ASIAN)
? maCJKFont
: ((nScript == css::i18n::ScriptType::COMPLEX)
? maCTLFont
: rInFont);
_pPrinter->SetFont(rFont);
rFont.DrawPrev(&rRenderContext, _pPrinter, rPt, maText, nStart, nEnd - nStart);
rPt.X() += maTextWidth[nIdx++];
if (nEnd < maText.getLength() && nIdx < nCnt)
{
nStart = nEnd;
nEnd = maScriptChg[nIdx];
nScript = maScriptType[nIdx];
}
else
break;
}
while(true);
_pPrinter->SetFont(aOldFont);
}
bool FontPrevWin_Impl::SetFontWidthScale(sal_uInt16 nScale)
{
if (mnFontWidthScale != nScale)
{
mnFontWidthScale = nScale;
return true;
}
return false;
}
void FontPrevWin_Impl::ScaleFontWidth(vcl::RenderContext& rOutDev)
{
if (!Is100PercentFontWidthValid())
{
scaleFontWidth(maFont, rOutDev, mn100PercentFontWidth);
scaleFontWidth(maCJKFont, rOutDev, mn100PercentFontWidthCJK);
scaleFontWidth(maCTLFont, rOutDev, mn100PercentFontWidthCTL);
}
maFont.SetAverageFontWidth(mn100PercentFontWidth * mnFontWidthScale / 100);
maCJKFont.SetAverageFontWidth(mn100PercentFontWidthCJK * mnFontWidthScale / 100);
maCTLFont.SetAverageFontWidth(mn100PercentFontWidthCTL * mnFontWidthScale / 100);
}
void SvxFontPrevWindow::ResetSettings(bool bForeground, bool bBackground)
{
mbResetForeground = bForeground;
mbResetBackground = bBackground;
Invalidate();
}
void SvxFontPrevWindow::ApplySettings(vcl::RenderContext& rRenderContext)
{
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
if (mbResetForeground)
{
svtools::ColorConfig aColorConfig;
Color aTextColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
if (IsControlForeground())
aTextColor = GetControlForeground();
rRenderContext.SetTextColor(aTextColor);
mbResetForeground = false;
}
if (mbResetBackground)
{
if (IsControlBackground())
rRenderContext.SetBackground(GetControlBackground());
else
rRenderContext.SetBackground(rStyleSettings.GetWindowColor());
mbResetBackground = false;
}
}
void SvxFontPrevWindow::Init()
{
pImpl.reset(new FontPrevWin_Impl);
SfxViewShell* pSh = SfxViewShell::Current();
if (pSh)
pImpl->mpPrinter = pSh->GetPrinter();
if (!pImpl->mpPrinter)
{
pImpl->mpPrinter = VclPtr<Printer>::Create();
pImpl->mbDelPrinter = true;
}
SetMapMode(MapMode(MapUnit::MapTwip));
initFont(pImpl->maFont);
initFont(pImpl->maCJKFont);
initFont(pImpl->maCTLFont);
ResetSettings(true, true);
SetBorderStyle(WindowBorderStyle::MONO);
}
SvxFontPrevWindow::SvxFontPrevWindow(vcl::Window* pParent, WinBits nStyle)
: Window(pParent, nStyle)
, mbResetForeground(true)
, mbResetBackground(true)
{
Init();
}
VCL_BUILDER_FACTORY_CONSTRUCTOR(SvxFontPrevWindow, 0)
SvxFontPrevWindow::~SvxFontPrevWindow()
{
disposeOnce();
}
void SvxFontPrevWindow::dispose()
{
pImpl.reset();
vcl::Window::dispose();
}
SvxFont& SvxFontPrevWindow::GetCTLFont()
{
return pImpl->maCTLFont;
}
SvxFont& SvxFontPrevWindow::GetCJKFont()
{
return pImpl->maCJKFont;
}
void SvxFontPrevWindow::StateChanged( StateChangedType nType )
{
if (nType == StateChangedType::ControlForeground)
ResetSettings(true, false);
else if (nType == StateChangedType::ControlBackground)
ResetSettings(false, true);
Window::StateChanged(nType);
Invalidate();
}
void SvxFontPrevWindow::DataChanged( const DataChangedEvent& rDCEvt )
{
if ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE))
ResetSettings(true, true);
else
Window::DataChanged( rDCEvt );
}
SvxFont& SvxFontPrevWindow::GetFont()
{
pImpl->Invalidate100PercentFontWidth(); // because the user might change the size
return pImpl->maFont;
}
const SvxFont& SvxFontPrevWindow::GetFont() const
{
return pImpl->maFont;
}
void SvxFontPrevWindow::SetPreviewText( const OUString& rString )
{
pImpl->maText = rString;
pImpl->mbTextInited = true;
}
void SvxFontPrevWindow::SetFontNameAsPreviewText()
{
pImpl->mbUseFontNameAsText = true;
}
void SvxFontPrevWindow::SetFont( const SvxFont& rNormalOutFont, const SvxFont& rCJKOutFont, const SvxFont& rCTLFont )
{
setFont(rNormalOutFont, pImpl->maFont);
setFont(rCJKOutFont, pImpl->maCJKFont);
setFont(rCTLFont, pImpl->maCTLFont);
pImpl->Invalidate100PercentFontWidth();
Invalidate();
}
void SvxFontPrevWindow::SetColor(const Color &rColor)
{
delete pImpl->mpColor;
pImpl->mpColor = new Color(rColor);
Invalidate();
}
void SvxFontPrevWindow::ResetColor()
{
delete pImpl->mpColor;
pImpl->mpColor = nullptr;
Invalidate();
}
void SvxFontPrevWindow::SetBackColor(const Color &rColor)
{
delete pImpl->mpBackColor;
pImpl->mpBackColor = new Color(rColor);
Invalidate();
}
void SvxFontPrevWindow::UseResourceText()
{
pImpl->mbUseResText = true;
}
void SvxFontPrevWindow::Paint(vcl::RenderContext& rRenderContext, const Rectangle&)
{
ApplySettings(rRenderContext);
Printer* pPrinter = pImpl->mpPrinter;
const SvxFont& rFont = pImpl->maFont;
const SvxFont& rCJKFont = pImpl->maCJKFont;
const SvxFont& rCTLFont = pImpl->maCTLFont;
if (!IsEnabled())
{
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
const Size aLogSize(rRenderContext.GetOutputSize());
Rectangle aRect(Point(0, 0), aLogSize);
rRenderContext.SetLineColor();
rRenderContext.SetFillColor(rStyleSettings.GetWindowColor());
rRenderContext.DrawRect(aRect);
}
else
{
if (pImpl->mbUseResText)
pImpl->maText = GetText();
else if (!pImpl->mbSelection && !pImpl->mbTextInited)
{
using namespace css::i18n::ScriptType;
SfxViewShell* pSh = SfxViewShell::Current();
if (pSh && !pImpl->mbGetSelection && !pImpl->mbUseFontNameAsText)
{
pImpl->maText = pSh->GetSelectionText();
pImpl->mbGetSelection = true;
pImpl->mbSelection = !pImpl->maText.isEmpty();
}
if (!pImpl->mbSelection || pImpl->mbUseFontNameAsText)
{
//If we're showing multiple sample texts, then they're all
//sample texts. If only showing Latin, continue to use
//the fontname as the preview
if ((pImpl->m_bCJKEnabled) || (pImpl->m_bCTLEnabled))
pImpl->maText = makeRepresentativeTextForFont(LATIN, rFont);
else
pImpl->maText = rFont.GetFamilyName();
if (pImpl->m_bCJKEnabled)
{
if (!pImpl->maText.isEmpty())
pImpl->maText += " ";
pImpl->maText += makeRepresentativeTextForFont(ASIAN, rCJKFont);
}
if (pImpl->m_bCTLEnabled)
{
if (!pImpl->maText.isEmpty())
pImpl->maText += " ";
pImpl->maText += makeRepresentativeTextForFont(COMPLEX, rCTLFont);
}
}
if (pImpl->maText.isEmpty())
pImpl->maText = GetText();
if (pImpl->maText.isEmpty())
{ // fdo#58427: still no text? let's try that one...
pImpl->maText = makeRepresentativeTextForFont(LATIN, rFont);
}
// remove line feeds and carriage returns from string
bool bNotEmpty = false;
for (sal_Int32 i = 0; i < pImpl->maText.getLength(); ++i)
{
if (0xa == pImpl->maText[i] || 0xd == pImpl->maText[i])
pImpl->maText = pImpl->maText.replaceAt(i, 1, " ");
else
bNotEmpty = true;
}
if (!bNotEmpty)
pImpl->maText = GetText();
if (pImpl->maText.getLength() > (TEXT_WIDTH - 1))
{
const sal_Int32 nSpaceIdx = pImpl->maText.indexOf(" ", TEXT_WIDTH);
if (nSpaceIdx != -1)
pImpl->maText = pImpl->maText.copy(0, nSpaceIdx);
else
pImpl->maText = pImpl->maText.copy(0, (TEXT_WIDTH - 1));
}
}
// calculate text width scaling
pImpl->ScaleFontWidth(rRenderContext);
pImpl->CheckScript();
Size aTxtSize = pImpl->CalcTextSize(rRenderContext, pPrinter, rFont);
const Size aLogSize(rRenderContext.GetOutputSize());
long nX = aLogSize.Width() / 2 - aTxtSize.Width() / 2;
long nY = aLogSize.Height() / 2 - aTxtSize.Height() / 2;
if (nY + pImpl->mnAscent > aLogSize.Height())
nY = aLogSize.Height() - pImpl->mnAscent;
if (pImpl->mpBackColor)
{
Rectangle aRect(Point(0, 0), aLogSize);
Color aLineCol = rRenderContext.GetLineColor();
Color aFillCol = rRenderContext.GetFillColor();
rRenderContext.SetLineColor();
rRenderContext.SetFillColor(*pImpl->mpBackColor);
rRenderContext.DrawRect(aRect);
rRenderContext.SetLineColor(aLineCol);
rRenderContext.SetFillColor(aFillCol);
}
if (pImpl->mpColor)
{
Rectangle aRect(Point(nX, nY), aTxtSize);
Color aLineCol = rRenderContext.GetLineColor();
Color aFillCol = rRenderContext.GetFillColor();
rRenderContext.SetLineColor();
rRenderContext.SetFillColor(*pImpl->mpColor);
rRenderContext.DrawRect(aRect);
rRenderContext.SetLineColor(aLineCol);
rRenderContext.SetFillColor(aFillCol);
}
long nStdAscent = pImpl->mnAscent;
nY += nStdAscent;
if (IsTwoLines())
{
SvxFont aSmallFont(rFont);
Size aOldSize = pImpl->maCJKFont.GetFontSize();
setFontSize(aSmallFont);
setFontSize(pImpl->maCJKFont);
long nStartBracketWidth = 0;
long nEndBracketWidth = 0;
long nTextWidth = 0;
if (pImpl->mcStartBracket)
{
OUString sBracket(pImpl->mcStartBracket);
nStartBracketWidth = rFont.GetTextSize(pPrinter, sBracket).Width();
}
if (pImpl->mcEndBracket)
{
OUString sBracket(pImpl->mcEndBracket);
nEndBracketWidth = rFont.GetTextSize(pPrinter, sBracket).Width();
}
nTextWidth = pImpl->CalcTextSize(rRenderContext, pPrinter, aSmallFont).Width();
long nResultWidth = nStartBracketWidth;
nResultWidth += nEndBracketWidth;
nResultWidth += nTextWidth;
long _nX = (aLogSize.Width() - nResultWidth) / 2;
rRenderContext.DrawLine(Point(0, nY), Point(_nX, nY));
rRenderContext.DrawLine(Point(_nX + nResultWidth, nY), Point(aLogSize.Width(), nY));
long nSmallAscent = pImpl->mnAscent;
long nOffset = (nStdAscent - nSmallAscent) / 2;
if (pImpl->mcStartBracket)
{
OUString sBracket(pImpl->mcStartBracket);
rFont.DrawPrev(&rRenderContext, pPrinter, Point(_nX, nY - nOffset - 4), sBracket);
_nX += nStartBracketWidth;
}
Point aTmpPoint1(_nX, nY - nSmallAscent - 2);
Point aTmpPoint2(_nX, nY);
pImpl->DrawPrev(rRenderContext, pPrinter, aTmpPoint1, aSmallFont);
pImpl->DrawPrev(rRenderContext, pPrinter, aTmpPoint2, aSmallFont);
_nX += nTextWidth;
if (pImpl->mcEndBracket)
{
Point aTmpPoint( _nX + 1, nY - nOffset - 4);
OUString sBracket(pImpl->mcEndBracket);
rFont.DrawPrev(&rRenderContext, pPrinter, aTmpPoint, sBracket);
}
pImpl->maCJKFont.SetFontSize(aOldSize);
}
else
{
Color aLineCol = rRenderContext.GetLineColor();
rRenderContext.SetLineColor(rFont.GetColor());
rRenderContext.DrawLine(Point(0, nY), Point(nX, nY));
rRenderContext.DrawLine(Point(nX + aTxtSize.Width(), nY), Point(aLogSize.Width(), nY));
rRenderContext.SetLineColor(aLineCol);
Point aTmpPoint(nX, nY);
pImpl->DrawPrev(rRenderContext, pPrinter, aTmpPoint, rFont);
}
}
}
bool SvxFontPrevWindow::IsTwoLines() const
{
return pImpl->mbTwoLines;
}
void SvxFontPrevWindow::SetTwoLines(bool bSet)
{
pImpl->mbTwoLines = bSet;
}
void SvxFontPrevWindow::SetBrackets(sal_Unicode cStart, sal_Unicode cEnd)
{
pImpl->mcStartBracket = cStart;
pImpl->mcEndBracket = cEnd;
}
void SvxFontPrevWindow::SetFontWidthScale( sal_uInt16 n )
{
if (pImpl->SetFontWidthScale(n))
Invalidate();
}
void SvxFontPrevWindow::AutoCorrectFontColor()
{
Color aFontColor( GetTextColor() );
if (COL_AUTO == pImpl->maFont.GetColor().GetColor())
pImpl->maFont.SetColor(aFontColor);
if (COL_AUTO == pImpl->maCJKFont.GetColor().GetColor())
pImpl->maCJKFont.SetColor(aFontColor);
if (COL_AUTO == pImpl->maCTLFont.GetColor().GetColor())
pImpl->maCTLFont.SetColor(aFontColor);
}
static bool GetWhich (const SfxItemSet& rSet, sal_uInt16 nSlot, sal_uInt16& rWhich)
{
rWhich = rSet.GetPool()->GetWhich(nSlot);
return rSet.GetItemState(rWhich) >= SfxItemState::DEFAULT;
}
static void SetPrevFont(const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont)
{
sal_uInt16 nWhich;
if (GetWhich(rSet, nSlot, nWhich))
{
const SvxFontItem& rFontItem = static_cast<const SvxFontItem&>(rSet.Get(nWhich));
rFont.SetFamily(rFontItem.GetFamily());
rFont.SetFamilyName(rFontItem.GetFamilyName());
rFont.SetPitch(rFontItem.GetPitch());
rFont.SetCharSet(rFontItem.GetCharSet());
rFont.SetStyleName(rFontItem.GetStyleName());
}
}
static void SetPrevFontStyle( const SfxItemSet& rSet, sal_uInt16 nPosture, sal_uInt16 nWeight, SvxFont& rFont )
{
sal_uInt16 nWhich;
if( GetWhich( rSet, nPosture, nWhich ) )
{
const SvxPostureItem& rItem = static_cast<const SvxPostureItem&>( rSet.Get( nWhich ) );
rFont.SetItalic( rItem.GetValue() != ITALIC_NONE ? ITALIC_NORMAL : ITALIC_NONE );
}
if( GetWhich( rSet, nWeight, nWhich ) )
{
const SvxWeightItem& rItem = static_cast<const SvxWeightItem&>( rSet.Get( nWhich ) );
rFont.SetWeight( rItem.GetValue() != WEIGHT_NORMAL ? WEIGHT_BOLD : WEIGHT_NORMAL );
}
}
void SvxFontPrevWindow::SetFontSize( const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont )
{
sal_uInt16 nWhich;
long nH;
if (GetWhich(rSet, nSlot, nWhich))
{
nH = LogicToLogic(static_cast<const SvxFontHeightItem&>(rSet.Get(nWhich)).GetHeight(),
(MapUnit) rSet.GetPool()->GetMetric(nWhich),
MapUnit::MapTwip);
}
else
nH = 240;// as default 12pt
rFont.SetFontSize(Size(0, nH));
}
void SvxFontPrevWindow::SetFontLang(const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont)
{
sal_uInt16 nWhich;
LanguageType nLang;
if( GetWhich( rSet, nSlot, nWhich ) )
nLang = static_cast<const SvxLanguageItem&>(rSet.Get(nWhich)).GetLanguage();
else
nLang = LANGUAGE_NONE;
rFont.SetLanguage(nLang);
}
static void SetPrevFontEscapement(SvxFont& rFont, sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc)
{
rFont.SetPropr(nProp);
rFont.SetProprRel(nEscProp);
rFont.SetEscapement(nEsc);
}
void SvxFontPrevWindow::SetFromItemSet(const SfxItemSet &rSet, bool bPreviewBackgroundToCharacter)
{
sal_uInt16 nWhich;
SvxFont& rFont = GetFont();
SvxFont& rCJKFont = GetCJKFont();
SvxFont& rCTLFont = GetCTLFont();
// Preview string
if( GetWhich( rSet, SID_CHAR_DLG_PREVIEW_STRING, nWhich ) )
{
const SfxStringItem& rItem = static_cast<const SfxStringItem&>( rSet.Get( nWhich ) );
const OUString& aString = rItem.GetValue();
if( !aString.isEmpty() )
SetPreviewText( aString );
else
SetFontNameAsPreviewText();
}
// Underline
FontLineStyle eUnderline;
if( GetWhich( rSet, SID_ATTR_CHAR_UNDERLINE, nWhich ) )
{
const SvxUnderlineItem& rItem = static_cast<const SvxUnderlineItem&>( rSet.Get( nWhich ) );
eUnderline = rItem.GetValue();
SetTextLineColor( rItem.GetColor() );
}
else
eUnderline = LINESTYLE_NONE;
rFont.SetUnderline( eUnderline );
rCJKFont.SetUnderline( eUnderline );
rCTLFont.SetUnderline( eUnderline );
// Overline
FontLineStyle eOverline;
if( GetWhich( rSet, SID_ATTR_CHAR_OVERLINE, nWhich ) )
{
const SvxOverlineItem& rItem = static_cast<const SvxOverlineItem&>( rSet.Get( nWhich ) );
eOverline = rItem.GetValue();
SetOverlineColor( rItem.GetColor() );
}
else
eOverline = LINESTYLE_NONE;
rFont.SetOverline( eOverline );
rCJKFont.SetOverline( eOverline );
rCTLFont.SetOverline( eOverline );
// Strikeout
FontStrikeout eStrikeout;
if( GetWhich( rSet, SID_ATTR_CHAR_STRIKEOUT, nWhich ) )
{
const SvxCrossedOutItem& rItem = static_cast<const SvxCrossedOutItem&>( rSet.Get( nWhich ) );
eStrikeout = rItem.GetValue();
}
else
eStrikeout = STRIKEOUT_NONE;
rFont.SetStrikeout( eStrikeout );
rCJKFont.SetStrikeout( eStrikeout );
rCTLFont.SetStrikeout( eStrikeout );
// WordLineMode
if( GetWhich( rSet, SID_ATTR_CHAR_WORDLINEMODE, nWhich ) )
{
const SvxWordLineModeItem& rItem = static_cast<const SvxWordLineModeItem&>( rSet.Get( nWhich ) );
rFont.SetWordLineMode( rItem.GetValue() );
rCJKFont.SetWordLineMode( rItem.GetValue() );
rCTLFont.SetWordLineMode( rItem.GetValue() );
}
// Emphasis
if( GetWhich( rSet, SID_ATTR_CHAR_EMPHASISMARK, nWhich ) )
{
const SvxEmphasisMarkItem& rItem = static_cast<const SvxEmphasisMarkItem&>( rSet.Get( nWhich ) );
FontEmphasisMark eMark = rItem.GetEmphasisMark();
rFont.SetEmphasisMark( eMark );
rCJKFont.SetEmphasisMark( eMark );
rCTLFont.SetEmphasisMark( eMark );
}
// Relief
if( GetWhich( rSet, SID_ATTR_CHAR_RELIEF, nWhich ) )
{
const SvxCharReliefItem& rItem = static_cast<const SvxCharReliefItem&>( rSet.Get( nWhich ) );
FontRelief eFontRelief = rItem.GetValue();
rFont.SetRelief( eFontRelief );
rCJKFont.SetRelief( eFontRelief );
rCTLFont.SetRelief( eFontRelief );
}
// Effects
if( GetWhich( rSet, SID_ATTR_CHAR_CASEMAP, nWhich ) )
{
const SvxCaseMapItem& rItem = static_cast<const SvxCaseMapItem&>( rSet.Get( nWhich ) );
SvxCaseMap eCaseMap = ( SvxCaseMap ) rItem.GetValue();
rFont.SetCaseMap( eCaseMap );
rCJKFont.SetCaseMap( eCaseMap );
// #i78474# small caps do not exist in CTL fonts
rCTLFont.SetCaseMap( eCaseMap == SvxCaseMap::SmallCaps ? SvxCaseMap::NotMapped : eCaseMap );
}
// Outline
if( GetWhich( rSet, SID_ATTR_CHAR_CONTOUR, nWhich ) )
{
const SvxContourItem& rItem = static_cast<const SvxContourItem&>( rSet.Get( nWhich ) );
bool bOutline = rItem.GetValue();
rFont.SetOutline( bOutline );
rCJKFont.SetOutline( bOutline );
rCTLFont.SetOutline( bOutline );
}
// Shadow
if( GetWhich( rSet, SID_ATTR_CHAR_SHADOWED, nWhich ) )
{
const SvxShadowedItem& rItem = static_cast<const SvxShadowedItem&>( rSet.Get( nWhich ) );
bool bShadow = rItem.GetValue();
rFont.SetShadow( bShadow );
rCJKFont.SetShadow( bShadow );
rCTLFont.SetShadow( bShadow );
}
// Background
bool bTransparent;
if( GetWhich( rSet, bPreviewBackgroundToCharacter ? SID_ATTR_BRUSH : SID_ATTR_BRUSH_CHAR, nWhich ) )
{
const SvxBrushItem& rBrush = static_cast<const SvxBrushItem&>( rSet.Get( nWhich ) );
const Color& rColor = rBrush.GetColor();
bTransparent = rColor.GetTransparency() > 0;
rFont.SetFillColor( rColor );
rCJKFont.SetFillColor( rColor );
rCTLFont.SetFillColor( rColor );
}
else
bTransparent = TRUE;
rFont.SetTransparent( bTransparent );
rCJKFont.SetTransparent( bTransparent );
rCTLFont.SetTransparent( bTransparent );
Color aBackCol( COL_TRANSPARENT );
if( !bPreviewBackgroundToCharacter )
{
if( GetWhich( rSet, SID_ATTR_BRUSH, nWhich ) )
{
const SvxBrushItem& rBrush = static_cast<const SvxBrushItem&>( rSet.Get( nWhich ) );
if( GPOS_NONE == rBrush.GetGraphicPos() )
aBackCol = rBrush.GetColor();
}
}
SetBackColor( aBackCol );
// Font
SetPrevFont( rSet, SID_ATTR_CHAR_FONT, rFont );
SetPrevFont( rSet, SID_ATTR_CHAR_CJK_FONT, rCJKFont );
SetPrevFont( rSet, SID_ATTR_CHAR_CTL_FONT, rCTLFont );
// Style
SetPrevFontStyle( rSet, SID_ATTR_CHAR_POSTURE, SID_ATTR_CHAR_WEIGHT, rFont );
SetPrevFontStyle( rSet, SID_ATTR_CHAR_CJK_POSTURE, SID_ATTR_CHAR_CJK_WEIGHT, rCJKFont );
SetPrevFontStyle( rSet, SID_ATTR_CHAR_CTL_POSTURE, SID_ATTR_CHAR_CTL_WEIGHT, rCTLFont );
// Size
SetFontSize( rSet, SID_ATTR_CHAR_FONTHEIGHT, rFont );
SetFontSize( rSet, SID_ATTR_CHAR_CJK_FONTHEIGHT, rCJKFont );
SetFontSize( rSet, SID_ATTR_CHAR_CTL_FONTHEIGHT, rCTLFont );
// Language
SetFontLang( rSet, SID_ATTR_CHAR_LANGUAGE, rFont );
SetFontLang( rSet, SID_ATTR_CHAR_CJK_LANGUAGE, rCJKFont );
SetFontLang( rSet, SID_ATTR_CHAR_CTL_LANGUAGE, rCTLFont );
// Color
if( GetWhich( rSet, SID_ATTR_CHAR_COLOR, nWhich ) )
{
const SvxColorItem& rItem = static_cast<const SvxColorItem&>( rSet.Get( nWhich ) );
Color aCol( rItem.GetValue() );
rFont.SetColor( aCol );
rCJKFont.SetColor( aCol );
rCTLFont.SetColor( aCol );
AutoCorrectFontColor(); // handle color COL_AUTO
}
// Kerning
if( GetWhich( rSet, SID_ATTR_CHAR_KERNING, nWhich ) )
{
const SvxKerningItem& rItem = static_cast<const SvxKerningItem&>( rSet.Get( nWhich ) );
short nKern = ( short )
LogicToLogic( rItem.GetValue(), ( MapUnit ) rSet.GetPool()->GetMetric( nWhich ), MapUnit::MapTwip );
rFont.SetFixKerning( nKern );
rCJKFont.SetFixKerning( nKern );
rCTLFont.SetFixKerning( nKern );
}
// Escapement
const sal_uInt8 nProp = 100;
short nEsc;
sal_uInt8 nEscProp;
if( GetWhich( rSet, SID_ATTR_CHAR_ESCAPEMENT, nWhich ) )
{
const SvxEscapementItem& rItem = static_cast<const SvxEscapementItem&>( rSet.Get( nWhich ) );
nEsc = rItem.GetEsc();
nEscProp = rItem.GetProportionalHeight();
if( nEsc == DFLT_ESC_AUTO_SUPER )
nEsc = DFLT_ESC_SUPER;
else if( nEsc == DFLT_ESC_AUTO_SUB )
nEsc = DFLT_ESC_SUB;
}
else
{
nEsc = 0;
nEscProp = 100;
}
SetPrevFontEscapement( rFont, nProp, nEscProp, nEsc );
SetPrevFontEscapement( rCJKFont, nProp, nEscProp, nEsc );
SetPrevFontEscapement( rCTLFont, nProp, nEscProp, nEsc );
// Font width scale
if( GetWhich( rSet, SID_ATTR_CHAR_SCALEWIDTH, nWhich ) )
{
const SvxCharScaleWidthItem&rItem = static_cast<const SvxCharScaleWidthItem&>( rSet.Get( nWhich ) );
SetFontWidthScale( rItem.GetValue() );
}
Invalidate();
}
void SvxFontPrevWindow::Init(const SfxItemSet& rSet)
{
SvxFont& rFont = GetFont();
SvxFont& rCJKFont = GetCJKFont();
SvxFont& rCTLFont = GetCTLFont();
initFont(rFont);
initFont(rCJKFont);
initFont(rCTLFont);
ResetSettings(true, true);
sal_uInt16 nWhich;
nWhich = rSet.GetPool()->GetWhich( SID_CHAR_DLG_PREVIEW_STRING );
if (ISITEMSET)
{
const SfxStringItem& rItem = static_cast<const SfxStringItem&>( rSet.Get( nWhich ) );
const OUString& aString = rItem.GetValue();
if( !aString.isEmpty() )
SetPreviewText( aString );
else
SetFontNameAsPreviewText();
}
// Underline
FontLineStyle eUnderline;
nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_UNDERLINE );
if( ISITEMSET )
{
const SvxUnderlineItem& rItem = static_cast<const SvxUnderlineItem&>( rSet.Get( nWhich ) );
eUnderline = rItem.GetValue();
SetTextLineColor( rItem.GetColor() );
}
else
eUnderline = LINESTYLE_NONE;
rFont.SetUnderline( eUnderline );
rCJKFont.SetUnderline( eUnderline );
rCTLFont.SetUnderline( eUnderline );
// Overline
FontLineStyle eOverline;
nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_OVERLINE );
if( ISITEMSET )
{
const SvxOverlineItem& rItem = static_cast<const SvxOverlineItem&>( rSet.Get( nWhich ) );
eOverline = rItem.GetValue();
SetOverlineColor( rItem.GetColor() );
}
else
eOverline = LINESTYLE_NONE;
rFont.SetOverline( eOverline );
rCJKFont.SetOverline( eOverline );
rCTLFont.SetOverline( eOverline );
// Strikeout
FontStrikeout eStrikeout;
nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_STRIKEOUT );
if( ISITEMSET )
{
const SvxCrossedOutItem& rItem = static_cast<const SvxCrossedOutItem&>( rSet.Get( nWhich ) );
eStrikeout = rItem.GetValue();
}
else
eStrikeout = STRIKEOUT_NONE;
rFont.SetStrikeout( eStrikeout );
rCJKFont.SetStrikeout( eStrikeout );
rCTLFont.SetStrikeout( eStrikeout );
// WordLineMode
nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_WORDLINEMODE );
if( ISITEMSET )
{
const SvxWordLineModeItem& rItem = static_cast<const SvxWordLineModeItem&>( rSet.Get( nWhich ) );
rFont.SetWordLineMode( rItem.GetValue() );
rCJKFont.SetWordLineMode( rItem.GetValue() );
rCTLFont.SetWordLineMode( rItem.GetValue() );
}
// Emphasis
nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_EMPHASISMARK );
if( ISITEMSET )
{
const SvxEmphasisMarkItem& rItem = static_cast<const SvxEmphasisMarkItem&>( rSet.Get( nWhich ) );
FontEmphasisMark eMark = rItem.GetEmphasisMark();
rFont.SetEmphasisMark( eMark );
rCJKFont.SetEmphasisMark( eMark );
rCTLFont.SetEmphasisMark( eMark );
}
// Relief
nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_RELIEF );
if( ISITEMSET )
{
const SvxCharReliefItem& rItem = static_cast<const SvxCharReliefItem&>( rSet.Get( nWhich ) );
FontRelief eFontRelief = rItem.GetValue();
rFont.SetRelief( eFontRelief );
rCJKFont.SetRelief( eFontRelief );
rCTLFont.SetRelief( eFontRelief );
}
// Effects
nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_CASEMAP );
if( ISITEMSET )
{
const SvxCaseMapItem& rItem = static_cast<const SvxCaseMapItem&>( rSet.Get( nWhich ) );
SvxCaseMap eCaseMap = ( SvxCaseMap ) rItem.GetValue();
rFont.SetCaseMap( eCaseMap );
rCJKFont.SetCaseMap( eCaseMap );
// #i78474# small caps do not exist in CTL fonts
rCTLFont.SetCaseMap( eCaseMap == SvxCaseMap::SmallCaps ? SvxCaseMap::NotMapped : eCaseMap );
}
// Outline
nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_CONTOUR );
if( ISITEMSET )
{
const SvxContourItem& rItem = static_cast<const SvxContourItem&>( rSet.Get( nWhich ) );
bool bOutline = rItem.GetValue();
rFont.SetOutline( bOutline );
rCJKFont.SetOutline( bOutline );
rCTLFont.SetOutline( bOutline );
}
// Shadow
nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_SHADOWED );
if( ISITEMSET )
{
const SvxShadowedItem& rItem = static_cast<const SvxShadowedItem&>( rSet.Get( nWhich ) );
bool bShadow = rItem.GetValue();
rFont.SetShadow( bShadow );
rCJKFont.SetShadow( bShadow );
rCTLFont.SetShadow( bShadow );
}
// Background
bool bTransparent;
nWhich = SID_ATTR_BRUSH_CHAR;
if (ISITEMSET)
{
const SvxBrushItem& rBrush = static_cast<const SvxBrushItem&>( rSet.Get( nWhich ) );
const Color& rColor = rBrush.GetColor();
bTransparent = rColor.GetTransparency() > 0;
rFont.SetFillColor(rColor);
rCJKFont.SetFillColor(rColor);
rCTLFont.SetFillColor(rColor);
}
else
bTransparent = true;
rFont.SetTransparent( bTransparent );
rCJKFont.SetTransparent( bTransparent );
rCTLFont.SetTransparent( bTransparent );
Color aBackCol( COL_TRANSPARENT );
nWhich = rSet.GetPool()->GetWhich( SID_ATTR_BRUSH );
if (ISITEMSET)
{
const SvxBrushItem& rBrush = static_cast<const SvxBrushItem&>(rSet.Get(nWhich));
if (GPOS_NONE == rBrush.GetGraphicPos())
aBackCol = rBrush.GetColor();
}
SetBackColor(aBackCol);
// Font
SetFont(rSet, SID_ATTR_CHAR_FONT, rFont);
SetFont(rSet, SID_ATTR_CHAR_CJK_FONT, rCJKFont);
SetFont(rSet, SID_ATTR_CHAR_CTL_FONT, rCTLFont);
// Style
SetFontStyle(rSet, SID_ATTR_CHAR_POSTURE, SID_ATTR_CHAR_WEIGHT, rFont);
SetFontStyle(rSet, SID_ATTR_CHAR_CJK_POSTURE, SID_ATTR_CHAR_CJK_WEIGHT, rCJKFont);
SetFontStyle(rSet, SID_ATTR_CHAR_CTL_POSTURE, SID_ATTR_CHAR_CTL_WEIGHT, rCTLFont);
// Size
SetFontSize(rSet, SID_ATTR_CHAR_FONTHEIGHT, rFont);
SetFontSize(rSet, SID_ATTR_CHAR_CJK_FONTHEIGHT, rCJKFont);
SetFontSize(rSet, SID_ATTR_CHAR_CTL_FONTHEIGHT, rCTLFont);
// Language
SetFontLang( rSet, SID_ATTR_CHAR_LANGUAGE, rFont );
SetFontLang( rSet, SID_ATTR_CHAR_CJK_LANGUAGE, rCJKFont );
SetFontLang( rSet, SID_ATTR_CHAR_CTL_LANGUAGE, rCTLFont );
// Color
nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_COLOR );
if( ISITEMSET )
{
const SvxColorItem& rItem = static_cast<const SvxColorItem&>( rSet.Get( nWhich ) );
Color aCol( rItem.GetValue() );
rFont.SetColor( aCol );
rCJKFont.SetColor( aCol );
rCTLFont.SetColor( aCol );
AutoCorrectFontColor(); // handle color COL_AUTO
}
// Kerning
nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_KERNING );
if( ISITEMSET )
{
const SvxKerningItem& rItem = static_cast<const SvxKerningItem&>( rSet.Get( nWhich ) );
short nKern = ( short )
LogicToLogic( rItem.GetValue(), ( MapUnit ) rSet.GetPool()->GetMetric( nWhich ), MapUnit::MapTwip );
rFont.SetFixKerning( nKern );
rCJKFont.SetFixKerning( nKern );
rCTLFont.SetFixKerning( nKern );
}
// Escapement
nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_ESCAPEMENT );
const sal_uInt8 nProp = 100;
short nEsc;
sal_uInt8 nEscProp;
if( ISITEMSET )
{
const SvxEscapementItem& rItem = static_cast<const SvxEscapementItem&>( rSet.Get( nWhich ) );
nEsc = rItem.GetEsc();
nEscProp = rItem.GetProportionalHeight();
if( nEsc == DFLT_ESC_AUTO_SUPER )
nEsc = DFLT_ESC_SUPER;
else if( nEsc == DFLT_ESC_AUTO_SUB )
nEsc = DFLT_ESC_SUB;
}
else
{
nEsc = 0;
nEscProp = 100;
}
SetFontEscapement( nProp, nEscProp, nEsc );
// Font width scale
SetFontWidthScale( rSet );
Invalidate();
}
void SvxFontPrevWindow::SetFont( const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont )
{
sal_uInt16 nWhich = rSet.GetPool()->GetWhich( nSlot );
if( ISITEMSET )
{
const SvxFontItem& rFontItem = static_cast<const SvxFontItem&>( rSet.Get(nWhich) );
rFont.SetFamily( rFontItem.GetFamily() );
rFont.SetFamilyName( rFontItem.GetFamilyName() );
rFont.SetPitch( rFontItem.GetPitch() );
rFont.SetCharSet( rFontItem.GetCharSet() );
rFont.SetStyleName( rFontItem.GetStyleName() );
}
}
void SvxFontPrevWindow::SetFontStyle( const SfxItemSet& rSet, sal_uInt16 nPosture, sal_uInt16 nWeight, SvxFont& rFont )
{
sal_uInt16 nWhich = rSet.GetPool()->GetWhich( nPosture );
if( ISITEMSET )
{
const SvxPostureItem& rItem = static_cast<const SvxPostureItem&>( rSet.Get( nWhich ) );
rFont.SetItalic( rItem.GetValue() != ITALIC_NONE ? ITALIC_NORMAL : ITALIC_NONE );
}
nWhich = rSet.GetPool()->GetWhich( nWeight );
if( ISITEMSET )
{
const SvxWeightItem& rItem = static_cast<const SvxWeightItem&>( rSet.Get( nWhich ) );
rFont.SetWeight( rItem.GetValue() != WEIGHT_NORMAL ? WEIGHT_BOLD : WEIGHT_NORMAL );
}
}
void SvxFontPrevWindow::SetFontWidthScale( const SfxItemSet& rSet )
{
sal_uInt16 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_SCALEWIDTH );
if( ISITEMSET )
{
const SvxCharScaleWidthItem& rItem = static_cast<const SvxCharScaleWidthItem&>( rSet.Get( nWhich ) );
SetFontWidthScale( rItem.GetValue() );
}
}
namespace
{
void setFontEscapement(SvxFont& rFont, sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc)
{
rFont.SetPropr(nProp);
rFont.SetProprRel(nEscProp);
rFont.SetEscapement(nEsc);
}
}
void SvxFontPrevWindow::SetFontEscapement(sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc)
{
setFontEscapement(GetFont(), nProp, nEscProp, nEsc);
setFontEscapement(GetCJKFont(), nProp, nEscProp, nEsc);
setFontEscapement(GetCTLFont(), nProp, nEscProp, nEsc);
Invalidate();
}
Size SvxFontPrevWindow::GetOptimalSize() const
{
return getPreviewStripSize(this);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|