-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathVwPropertyStore.cpp
More file actions
2770 lines (2516 loc) · 92.8 KB
/
Copy pathVwPropertyStore.cpp
File metadata and controls
2770 lines (2516 loc) · 92.8 KB
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
/*-----------------------------------------------------------------------*//*:Ignore in Surveyor
Copyright (c) 1999-2013 SIL International
This software is licensed under the LGPL, version 2.1 or later
(http://www.gnu.org/licenses/lgpl-2.1.html)
File: VwPropertyStore.cpp
Responsibility: John Thomson
Last reviewed: Not yet.
Description:
Store computed values of all the formatting properties, together with maps linking
this store to related ones.
-------------------------------------------------------------------------------*//*:End Ignore*/
//:>********************************************************************************************
//:> Include files
//:>********************************************************************************************
#include "Main.h"
#pragma hdrstop
#undef THIS_FILE
DEFINE_THIS_FILE
int VwPropertyStore::totalrefs = 0;
//:>********************************************************************************************
//:> Forward declarations
//:>********************************************************************************************
//:>********************************************************************************************
//:> Local Constants and static variables
//:>********************************************************************************************
static int g_rgnFontSizes[] = {
5000, // kvfsXXSmall
7000, // kvfsXSmall
9000, // kvfsSmall
12000, // kvfsNormal
14000, // kvfsLarge
18000, // kvfsXLarge
24000 // kvfsXXLarge
};
// kvfsSmaller and kvfsLarger don't have absolute values
static int knDefaultFontSize = 10000; // 10 point default
// The order of these is signficant--it is the order the font properties are recorded in
// for each writing system, in the wsStyle string.
// A copy of this list is in VwPropertyStore.cpp -- the two lists must be kept in sync.
static const int s_rgtptWsStyleProps[] = {
ktptFontSize, ktptBold, ktptItalic, ktptSuperscript,
ktptForeColor, ktptBackColor, ktptUnderColor, ktptUnderline, ktptOffset
};
static const int s_ctptWsStyleProps = (isizeof(s_rgtptWsStyleProps) / isizeof(int));
// Magic font strings that are used in markup:
static OleStringLiteral g_pszDefaultFont(L"<default font>");
//:>********************************************************************************************
//:> DllExports
//:>********************************************************************************************
extern "C" _declspec(dllexport) void* VwPropertyStore_Create() {
return (void*)NewObj VwPropertyStore();
}
extern "C" _declspec(dllexport) void VwPropertyStore_Delete(VwPropertyStore* t) {
delete t;
}
extern "C" _declspec(dllexport) void VwPropertyStore_Stylesheet(VwPropertyStore* t, IVwStylesheet* pss) {
t->putref_Stylesheet(pss);
}
extern "C" _declspec(dllexport) void VwPropertyStore_WritingSystemFactory(VwPropertyStore* t, ILgWritingSystemFactory* pwsf) {
t->putref_WritingSystemFactory(pwsf);
}
extern "C" _declspec(dllexport) LgCharRenderProps* VwPropertyStore_get_ChrpFor(VwPropertyStore* t, ITsTextProps* pttp) {
LgCharRenderProps* pchrp = NewObj LgCharRenderProps();
t->get_ChrpFor(pttp, pchrp);
return pchrp;
}
//:>********************************************************************************************
//:> Constructor/Destructor
//:>********************************************************************************************
CachedProps::CachedProps()
{
memset(this, 0, isizeof(this));
}
/*----------------------------------------------------------------------------------------------
Init common to constructor and SetInitialState.
----------------------------------------------------------------------------------------------*/
void VwPropertyStore::CommonInit()
{
m_stuFontFamily = (OLECHAR*)g_pszDefaultFont;
// m_stuWsStyle is self-initialized to empty
m_nWeight = kvfwNormal;
m_chrp.dympHeight = knDefaultFontSize;
m_chrp.m_unt = kuntNone;
m_chrp.m_clrUnder = (unsigned long) kclrTransparent; // cheat: means same as foreground
#if defined(WIN32) || defined(WIN64)
m_chrp.clrFore = m_clrBorderColor = ::GetSysColor(COLOR_WINDOWTEXT);
#else //WIN32
// set to default black RGB color
m_chrp.clrFore = m_clrBorderColor = RGB(0,0,0);
#endif //WIN32
m_chrp.clrBack = (unsigned long) kclrTransparent;
m_nNumStartAt = INT_MIN; // a very unlikely value to signify not specified.
m_fEditable = ktptIsEditable;
m_ta = ktalLeading; // This is actually 0, but play safe.
m_smSpellMode = ksmNormalCheck; // also zero.
}
/*----------------------------------------------------------------------------------------------
RE-create the initial state of a newly constructed property store, except:
- don't alter ref count, locked status, parent, maps, reset, key.
----------------------------------------------------------------------------------------------*/
void VwPropertyStore::SetInitialState()
{
ClearItems(&m_chrp, 1); // zeros everything in m_chrp
CommonInit();
m_stuWsStyle.Clear();
m_cactBolder = 0;
m_fRightToLeft = FALSE;
m_stuFontVariations.Clear();
m_mpMswMarginTop = 0;
m_mpMarginTop = m_mpMarginBottom = m_mpMarginLeading = m_mpMarginTrailing = 0;
m_stuTags.Clear();
m_mpPadTop = m_mpPadBottom = m_mpPadLeading = m_mpPadTrailing = 0;
m_mpBorderTop = m_mpBorderBottom = m_mpBorderLeading = m_mpBorderTrailing = 0;
m_clrBorderColor = 0;
m_vbnBulNumScheme = 0;
m_stuNumTxtBef.Clear();
m_stuNumTxtAft.Clear();
m_stuNumFontInfo.Clear();
m_mpFirstIndent = 0;
m_mpLineHeight = 0; // default is just enough for font height
m_nRelLineHeight = 0; // default is absolute
m_mpTableBorder = m_mpTableSpacing = m_mpTablePadding = 0;
m_vwrule = (VwRule) 0;
m_nMaxLines = 0; // interpreted as unlimited
m_fKeepWithNext = FALSE;
m_fKeepTogether = FALSE;
m_fWidowOrphanControl = TRUE; // default should be true
m_fHyphenate = FALSE;
m_grfcsExplicitMargins = (CellSides) 0;
m_pzvpsParent = 0;
m_ws = m_wsBase = 0;
}
VwPropertyStore::VwPropertyStore()
{
m_cref = 1;
ModuleEntry::ModuleAddRef();
m_fLocked = false;
Assert(m_cactBolder == 0);
Assert(m_mpMarginTop == 0);
Assert(m_grfcsExplicitMargins == 0);
Assert(m_nMaxLines == 0); // interpreted as unlimited
Assert(m_pzvpsParent == 0);
CommonInit();
}
VwPropertyStore::~VwPropertyStore()
{
ModuleEntry::ModuleRelease();
// Call DisconnectParent on all children: forces them to get rid of their
// (uncounted) pointer to this.
for (int ispr = 0; ispr < m_vstrprrec.Size(); ++ispr)
{
m_vstrprrec[ispr].m_pzvps->DisconnectParent();
// m_vstrprrec[ispr].m_pzvps->Release(); No! Destructor of Vector and StrPropRec does it!
}
MapTtpPropStore::iterator ithmvprzvps;
for (ithmvprzvps = m_hmttpzvps.Begin();
ithmvprzvps != m_hmttpzvps.End();
++ithmvprzvps)
{
ithmvprzvps.GetValue()->DisconnectParent();
}
MapIPKPropStore::iterator ithmipkzvps;
for (ithmipkzvps = m_hmipkzvps.Begin();
ithmipkzvps != m_hmipkzvps.End();
++ithmipkzvps)
{
ithmipkzvps.GetValue()->DisconnectParent();
}
#if !defined(_WIN32) && !defined(_M_X64)
// work around TeDllTests hang on exit
if (m_qwsf)
m_qwsf.Detach();
#endif
}
//:>********************************************************************************************
//:> IUnknown Methods
//:>********************************************************************************************
STDMETHODIMP VwPropertyStore::QueryInterface(REFIID riid, void **ppv)
{
AssertPtr(ppv);
if (!ppv)
return WarnHr(E_POINTER);
*ppv = NULL;
if (riid == IID_IUnknown)
*ppv = static_cast<IUnknown *>(this);
else if (riid == IID_IVwPropertyStore)
*ppv = static_cast<IVwPropertyStore *>(this);
else if (riid == IID_ISupportErrorInfo)
{
*ppv = NewObj CSupportErrorInfo(this, IID_IVwPropertyStore);
return S_OK;
}
else
return E_NOINTERFACE;
AddRef();
return NOERROR;
}
//:>********************************************************************************************
//:> Generic factory stuff to allow creating an instance with CoCreateInstance.
//:>********************************************************************************************
static GenericFactory g_factVps(
_T("SIL.Views.VwPropertyStore"),
&CLSID_VwPropertyStore,
_T("SIL Property Store"),
_T("Apartment"),
&VwPropertyStore::CreateCom);
void VwPropertyStore::CreateCom(IUnknown *punkCtl, REFIID riid, void ** ppv)
{
AssertPtr(ppv);
Assert(!*ppv);
if (punkCtl)
ThrowHr(WarnHr(CLASS_E_NOAGGREGATION));
ComSmartPtr<VwPropertyStore> qvps;
qvps.Attach(NewObj VwPropertyStore()); // ref count initialy 1
qvps->Lock(); // This will be a root store and should be initially locked.
CheckHr(qvps->QueryInterface(riid, ppv));
}
VwPropertyStore * VwPropertyStore::MakePropertyStore()
{
return NewObj VwPropertyStore();
}
//:>********************************************************************************************
//:> IVwTextPropertyMap Interface Methods
//:>********************************************************************************************
/*----------------------------------------------------------------------------------------------
Get the actual text properties object associated with the given key (actually a
TxTextProps, typically), if any. Caller is responsible to Release once.
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_ChrpFor(ITsTextProps * pttp, LgCharRenderProps * pchrp)
{
BEGIN_COM_METHOD;
ChkComArgPtr(pttp);
ChkComArgPtr(pchrp);
VwPropertyStore * pvps = PropertiesForTtp(pttp);
pvps->GetChrp(pchrp);
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
CachedProps * VwPropertyStore::Chrp()
{
if (!m_fInitChrp)
{
InitChrp();
}
return &m_chrp;
}
CachedProps * VwPropertyStore::ChrpFor(ITsTextProps * pttp)
{
return PropertiesForTtp(pttp)->Chrp();
}
void VwPropertyStore::GetChrp(LgCharRenderProps * pchrp)
{
if (!m_fInitChrp)
{
InitChrp();
}
CopyBytes(&m_chrp, pchrp, isizeof(LgCharRenderProps));
}
/*----------------------------------------------------------------------------------------------
Create the writing system factory if it does not yet exist.
----------------------------------------------------------------------------------------------*/
void VwPropertyStore::EnsureWritingSystemFactory()
{
if (!m_qwsf)
{
AssertPtr(m_qss);
ISilDataAccessPtr qsda;
CheckHr(m_qss->get_DataAccess(&qsda));
AssertPtr(qsda);
CheckHr(qsda->get_WritingSystemFactory(&m_qwsf));
}
AssertPtr(m_qwsf);
}
/*----------------------------------------------------------------------------------------------
Compute an adjusted line height (in mp) that is
- the exact line height the user specified, if using exact line height
- otherwise, the max of the line height the user specified and the
height of the height of the font.
Also optionally returns some font metrics based on this property store, but using the
writing system and font family from the specified leaf property store (since this property
store is presumably that of a paragraph (which means it won't have a real WS and might
have a magic font name).
----------------------------------------------------------------------------------------------*/
int VwPropertyStore::AdjustedLineHeight(VwPropertyStore * pzvpsLeaf, int * pdympAscent,
int * pdympDescent, int * pdympEmHeight)
{
VwPropertyStorePtr qzvpsWithWsAndFont;
qzvpsWithWsAndFont.Attach(MakePropertyStore());
qzvpsWithWsAndFont->CopyInheritedFrom(this);
qzvpsWithWsAndFont->m_stuFontFamily = pzvpsLeaf->m_stuFontFamily;
qzvpsWithWsAndFont->m_chrp.ws = pzvpsLeaf->m_chrp.ws;
qzvpsWithWsAndFont->Lock();
#if defined(WIN32) || defined(WIN64)
// We want to make some measurements on the font. They don't have to be super precise,
// so we'll just use a current screen DC.
HDC hdc = AfGdi::GetDC(NULL);
int dpiY = ::GetDeviceCaps(hdc, LOGPIXELSY);
LgCharRenderProps * pchrp = qzvpsWithWsAndFont->Chrp();
// This is very similar to code in VwGraphics::SetupGraphics, but we don't have
// an IVwGraphics here so I don't see how to share it.
LOGFONT lf;
lf.lfItalic = pchrp->ttvItalic == kttvOff ? false : true;
lf.lfWeight = pchrp->ttvBold == kttvOff ? 400 : 700;
// The minus causes this to be the font height (roughly, from top of ascenders
// to bottom of descenders). A positive number indicates we want a font with
// this distance as the total line spacing, which makes them too small.
lf.lfHeight = -MulDiv(pchrp->dympHeight, dpiY, kdzmpInch);
lf.lfUnderline = false;
lf.lfWidth = 0; // default width, based on height
lf.lfEscapement = 0; // no rotation of text (is this how to do slanted?)
lf.lfOrientation = 0; // no rotation of character baselines
lf.lfStrikeOut = 0; // not strike-out
lf.lfCharSet = DEFAULT_CHARSET; // let name determine it; WS should specify valid
lf.lfOutPrecision = OUT_TT_ONLY_PRECIS; // only work with TrueType fonts
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; // ??
lf.lfQuality = DRAFT_QUALITY; // I (JohnT) don't think this matters for TrueType fonts.
lf.lfPitchAndFamily = 0; // must be zero for EnumFontFamiliesEx
wcscpy_s(lf.lfFaceName, LF_FACESIZE, pchrp->szFaceName);
qzvpsWithWsAndFont->Unlock();
HFONT hfont;
hfont = AfGdi::CreateFontIndirect(&lf);
if (!hfont)
ThrowHr(WarnHr(E_FAIL));
AfGdi::SelectObjectFont(hdc, hfont);
int tmAscent;
int tmDescent;
int tmEmHeight;
OUTLINETEXTMETRIC otm;
if (::GetOutlineTextMetrics(hdc, sizeof(OUTLINETEXTMETRIC), &otm))
{
tmAscent = otm.otmAscent;
tmDescent = -otm.otmDescent;
tmEmHeight = otm.otmsCapEmHeight;
}
else
{
TEXTMETRIC tm;
if (::GetTextMetrics(hdc, &tm))
{
tmAscent = tm.tmAscent;
tmDescent = tm.tmDescent;
// This is not guaranteed to be the EM height because it assumes the internal leading is
// all above the baseline. This is typically mostly true for many fonts.
tmEmHeight = tmAscent - tm.tmInternalLeading;
}
else
{
// We can't get the information in a useful way, so just guess. (TE-6764)
// The calculations are based on the font values we tested at 10 and 20 point
// font sizes. Hopefully this will create a result that looks fairly accurate.
tmAscent = (int)(abs(lf.lfHeight) * 0.7);
tmDescent = (int)(abs(lf.lfHeight) * 0.25);
tmEmHeight = (int)(abs(lf.lfHeight) * 0.5);
}
}
AfGdi::DeleteObjectFont(hfont);
AfGdi::ReleaseDC(NULL, hdc);
#else
int dpiY = GetDpiY(NULL);
// TODO-Linux: Only the fallback route has been ported like done for (TE-6764)
LgCharRenderProps * pchrp = qzvpsWithWsAndFont->Chrp();
int height = -MulDiv(pchrp->dympHeight, dpiY, kdzmpInch);
qzvpsWithWsAndFont->Unlock();
int tmAscent;
int tmDescent;
int tmEmHeight;
if(!pzvpsLeaf->DropCaps())
{
IVwGraphicsWin32Ptr qvg;
qvg.CreateInstance(CLSID_VwGraphicsWin32);
qvg->Initialize(NULL);
CheckHr(qvg->SetupGraphics(pchrp));
qvg->get_FontAscent(&tmAscent);
qvg->get_FontDescent(&tmDescent);
// TODO-Linux: (FWNX-80) we have to implement this to get the LBearing
// from the font matrix. For now internaleading or LBearing is defaulted to 0
int tmInternalLeading = 0;
tmEmHeight = tmAscent - tmInternalLeading;
}
else
{
tmAscent = (int)(abs(height) * 0.7);
tmDescent = (int)(abs(height) * 0.25);
tmEmHeight = (int)(abs(height) * 0.5);
}
Assert(tmEmHeight > 0);
#endif
int dympAscent = MulDiv(tmAscent, kdzmpInch, dpiY);
int dympDescent = MulDiv(tmDescent, kdzmpInch, dpiY);
if (pdympAscent)
*pdympAscent = dympAscent;
if (pdympDescent)
*pdympDescent = dympDescent;
if (pdympEmHeight)
*pdympEmHeight = MulDiv(tmEmHeight, kdzmpInch, dpiY);
if (ExactLineHeight())
return LineHeight();
int dympLineHeight = LineHeight();
if (dympLineHeight < dympAscent + dympDescent)
dympLineHeight = dympAscent + dympDescent;
return dympLineHeight;
}
/*----------------------------------------------------------------------------------------------
This is called for a 'leaf' property store when it is about to be used for actual
rendering. It figures out what chrp should actually be passed to the writing system
to figure out what renderer to use, and is then passed on to the renderer itself to do
the actual drawing.
Currently this means simplifying the weight information to a true/false value for bold;
fill in the direction and depth fields in the chrp;
and get the writing system to interpret any magic font names.
Also, if DropCaps is on, figure a modified font size.
----------------------------------------------------------------------------------------------*/
void VwPropertyStore::InitChrp()
{
Assert(m_fLocked); // Must be locked, we won't figure it again.
EnsureWritingSystemFactory();
m_chrp.ttvBold = (byte)((m_nWeight > 400) ? kttvForceOn : kttvOff);
// All the above is trivial. However, finding a real font name is a bit more
// interesting...theoretically the views code allows us to have a comma-separated
// list of fonts here, in which case we should use the first one installed...
// for now we just use the first one if we find a list.
const wchar * pch = m_stuFontFamily;
for ( ; ; )
{
pch = StrUtil::SkipLeadingWhiteSpace(pch);
const wchar * pchStartName = pch;
while (*pch && !(*pch == ','))
pch++;
if (pch == pchStartName)
{
// Got no useable font name. Substitute <default> and let the WS
// find a useable font.
static OleStringLiteral defaultName(L"<default>");
wcscpy_s(m_chrp.szFaceName, LF_FACESIZE, defaultName); // TODO: should this use FwStyledText::FontDefaultMarkup()?
break;
}
// If we get here we have either a valid, installed font name, or a
// standard magic name. In either case, just use it.
int cchCopy = (int)(pch - pchStartName);
if (cchCopy > 31)
cchCopy = 31;
wcsncpy_s(m_chrp.szFaceName, 32, pchStartName, cchCopy);
m_chrp.szFaceName[cchCopy] = 0; // ensure null termination
break;
}
// Figure the ws direction and note it in the chrp.
ILgWritingSystemPtr qws;
if (!m_chrp.ws)
CheckHr(m_qwsf->get_UserWs(&m_chrp.ws)); // Get default writing system id.
Assert(m_chrp.ws);
CheckHr(m_qwsf->get_EngineOrNull(m_chrp.ws, &qws));
AssertPtr(qws);
ComBool fRtl;
CheckHr(qws->get_RightToLeftScript(&fRtl));
m_chrp.fWsRtl = (bool)fRtl;
m_chrp.nDirDepth = (fRtl) ? 1 : 0;
// Interpret any magic font names.
CheckHr(qws->InterpretChrp(&m_chrp));
// Other fields in m_chrp have the exact same meaning as the corresponding property,
// and are already used to store it.
if (DropCaps())
{
// If we're not careful here, we can get into an infinite recursion, because
// AdjustedLineHeight() calls Chrp() on a new property store, which calls InitChrp(),
// which can repeat until the stack overflows and the program silently disappears.
// See LT-8904 for how this can be triggered.
// If the parent property store already has the ws and font family set, and is also set
// for "Drop Caps", then it also already has the dympHeight set properly.
if (!m_pzvpsParent->DropCaps() ||
m_pzvpsParent->m_chrp.ws == 0 ||
m_pzvpsParent->m_stuFontFamily.Length() == 0)
{
int dympAscent;
int dympDescent;
// The EM Height is the ascent minus portion of the 'Internal Leading' that is above the baseline
// (Many/most/all TrueType fonts just report this as the otmEMSquare value)
int dympEmHeight;
int dympLineHeight = m_pzvpsParent->AdjustedLineHeight(this,
&dympAscent, &dympDescent, &dympEmHeight);
// Adding the baseline separation gives the desired internal ascent of the drop cap.
int dympDropCapEmHeight = dympEmHeight + dympLineHeight;
int dympDropCapDescent = dympDescent * dympDropCapEmHeight / dympEmHeight;
// when we request a font height, we request the total height (ascent + descent), minus the
// internal leading
int dympDropCapHeightToRequest = dympDropCapEmHeight + dympDropCapDescent;
// Using that as the 'point size' of the font may make it look about right...
// But it doesn't, so we need to do two more things:
// First, we observe that some fonts don't return a physical font having the requested logical size, so
// we calculate a factor that takes this into account.
// Second, we use a universal fudge factor that makes everything right...
#if defined(WIN32) || defined(WIN64)
HDC hdc = AfGdi::GetDC(NULL);
int dpiY = ::GetDeviceCaps(hdc, LOGPIXELSY);
#else
int dpiY = GetDpiY(NULL);
#endif
double requestedToReceivedRatio = m_pzvpsParent->m_chrp.dympHeight * kdzmpInch / (dpiY * 1000.0 * (dympDescent + dympEmHeight));
#if defined(WIN32) || defined(WIN64)
AfGdi::ReleaseDC(NULL, hdc);
#endif
double fudgeFactor = 1.125;
m_chrp.dympHeight = (int)(dympDropCapHeightToRequest * fudgeFactor * requestedToReceivedRatio);
}
else
{
Assert(m_chrp.ws == m_pzvpsParent->m_chrp.ws);
Assert(m_stuFontFamily == m_pzvpsParent->m_stuFontFamily);
}
// Our goal here is to use the information obtained above to figure
// m_chrp.dympHeight, which is the ascent in millipoints (mp) of the
// drop caps font.
// We'd basically like this to fill the space from the top of the paragraph
// down to the baseline of the second line. That's one complete line plus
// the font ascent.
// This '1.7 * line height plus ascent' has worked best so far.
//m_chrp.dympHeight = dympLineHeight * 170 / 100 + dympAscent;
//m_chrp.dympHeight = dympLineHeight + dympAscent;
//int dmpHeight1 = dympLineHeight + dympAscent;
//// However, we also want to try to avoid a situation where the ascent plus
//// descent of the drop cap is greater than twice the line height. The ascent
//// we compute here is one that would make the drop cap's total height (including
//// descenders) two full lines at the paragraph default font size.
//int dmpHeight2 = dympLineHeight * 2 * dympAscent / (dympAscent + dympDescent);
//// The min of those seems to give the best overall result.
//// Review: consider taking the max of this and the original height, currently stored
//// in m_chrp.dympHeight.
//m_chrp.dympHeight = min(dmpHeight1, dmpHeight2);
}
m_fInitChrp = true; // last, once we got it all figured.
}
void VwPropertyStore::GetUnderlineInfo(int * punt, COLORREF * pclr)
{
*punt = m_chrp.m_unt;
*pclr = m_chrp.m_clrUnder;
}
//:>********************************************************************************************
//:> IVwComputedProperty Interface Methods
//:>********************************************************************************************
/*----------------------------------------------------------------------------------------------
Tells (from the writing system) whether it is necessary to use multiple distinct fonts to
render different ranges of code points for the current writing system. Delegated to the
writing system.
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_UsesMultipleFonts(ComBool *pf)
{
BEGIN_COM_METHOD;
ChkComOutPtr(pf);
#if 0 // ENHANCE: reinstate something like this if we implement writing systems that use
// multiple fonts.
if (!m_pwse) {
Warn("premature use of ws-dependent method");
return E_UNEXPECTED;
}
IRenderEngine * preneng;
IgnoreHr(hr = m_pwse->Renderer(&preneng));
if (FAILED(hr))
{
Warn("writing system w/o renderer");
return E_FAIL;
}
return preneng->get_UsesMultipleFonts(pf);
#else // placeholder, delete eventually
*pf = FALSE;
#endif // placeholder
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
// For greater efficiency the most common properties have
// individual methods.
/*----------------------------------------------------------------------------------------------
Get the font name(s) to use to display text using these computed properties.
@param pbstr A comma-separated list of fonts
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_FontFamily(BSTR * pbstr)
{
BEGIN_COM_METHOD;
ChkComOutPtr(pbstr);
if (m_stuFontFamily.Length() == 0)
{
static OleStringLiteral serif(L"<serif>");
*pbstr = SysAllocString(serif); // last ditch default
if (*pbstr)
return S_OK;
else
return E_OUTOFMEMORY;
}
CopyBstr(pbstr, m_stuFontFamily.Bstr());
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
/*----------------------------------------------------------------------------------------------
Normal, italic, slanted
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_FontStyle(ComBool * pf)
{
BEGIN_COM_METHOD;
ChkComOutPtr(pf);
*pf = m_chrp.ttvItalic;
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
/*----------------------------------------------------------------------------------------------
Get how bold to make the font
@param pnWeight A number from 0 to 1000 where 400 is normal, 700 bold
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_FontWeight(int * pnWeight)
{
BEGIN_COM_METHOD;
ChkComOutPtr(pnWeight);
*pnWeight = m_nWeight;
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
/*----------------------------------------------------------------------------------------------
Get the number of requests for bolder (or -ve, lighter). We can't apply this info at once,
because it is the actual text property thing that works out which fonts are even available.
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_FontWeightIncrements(int * pcactBolder)
{
BEGIN_COM_METHOD;
ChkComOutPtr(pcactBolder);
*pcactBolder = m_cactBolder;
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
/*----------------------------------------------------------------------------------------------
The font size to try for
@param pnP1000 In thousandths of a point
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_FontSize(int * pnP1000)
{
BEGIN_COM_METHOD;
ChkComOutPtr(pnP1000);
*pnP1000 = m_chrp.dympHeight;
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
/*----------------------------------------------------------------------------------------------
Get the superscripting to use (-ve for subscript)
@param pnP1000 In thousandths of a point
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_FontSuperscript(int * pnP1000)
{
BEGIN_COM_METHOD;
ChkComOutPtr(pnP1000);
*pnP1000 = m_chrp.dympOffset;
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
/*----------------------------------------------------------------------------------------------
Get whether the old writing system is primarily right-to-left
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_RightToLeft(ComBool * pfRet)
{
BEGIN_COM_METHOD;
ChkComOutPtr(pfRet);
*pfRet = m_fRightToLeft;
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
/*----------------------------------------------------------------------------------------------
Get how many levels of direction change are implied by all the properties here
@param pn # of embedded direction changes
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_DirectionDepth(int * pn)
{
BEGIN_COM_METHOD;
ChkComOutPtr(pn);
*pn = m_chrp.nDirDepth;
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
/*----------------------------------------------------------------------------------------------
This is a property that allows special customizations of rendering with WinRend and
GX fonts (when implmented).
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_FontVariations(BSTR * pbstr)
{
BEGIN_COM_METHOD;
ChkComOutPtr(pbstr);
CopyBstr(pbstr, m_stuFontFamily.Bstr());
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
/*----------------------------------------------------------------------------------------------
Color used for text and lines (including borders of figures)
@param pnRGB RGB color value
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_ForeColor(int * pnRGB)
{
BEGIN_COM_METHOD;
ChkComOutPtr(pnRGB);
*pnRGB = m_chrp.clrFore;
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
/*----------------------------------------------------------------------------------------------
Color used for text background and figure fill
@param pnRGB RGB color value or kclrTransparent
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_BackColor(int * pnRGB)
{
BEGIN_COM_METHOD;
ChkComOutPtr(pnRGB);
*pnRGB = m_chrp.clrBack;
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
/*----------------------------------------------------------------------------------------------
Read any int propery
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_IntProperty(int nID, int * pnValue)
{
BEGIN_COM_METHOD;
ChkComOutPtr(pnValue);
switch(nID)
{
case ktptAlign:
*pnValue = m_ta;
break;
case ktptItalic:
if (m_chrp.ttvItalic == kttvInvert)
{
// NOTE: This code will probably not get called since
// VwPropertyStore::put_IntProperty() case kttvInvert:
// no longer allows m_chrp.ttvItalic to be set to kttvInvert.
VwPropertyStore * pvps = m_pzvpsParent;
int iInv = 1;
while ((pvps->m_chrp.ttvItalic == kttvInvert) && (iInv < 100))
{
iInv++; // count the inversions
pvps = pvps->m_pzvpsParent;
}
Assert(iInv <= 1);
int tmp = pvps->m_chrp.ttvItalic;
for (int i=0; i < iInv; i++)
{
// invert
if (tmp == kttvOff)
tmp = kttvForceOn;
else
tmp = kttvOff;
}
*pnValue = tmp;
}
else
*pnValue = m_chrp.ttvItalic;
break;
case ktptBold:
// Assert(m_chrp.fBold == (m_nWeight > 550)); // can happen, but shouldn't
*pnValue = m_nWeight;
// *pnValue = m_chrp.fBold ? kttvForceOn : kttvOff;
break;
case ktptFontSize:
*pnValue = m_chrp.dympHeight;
break;
case ktptSuperscript:
*pnValue = m_chrp.ssv;
break;
case ktptOffset:
*pnValue = m_chrp.dympOffset;
break;
case ktptUnderline:
*pnValue = m_chrp.m_unt;
break;
case ktptUnderColor:
*pnValue = m_chrp.m_clrUnder;
break;
case ktptRightToLeft:
*pnValue = m_fRightToLeft;
break;
case ktptDirectionDepth:
*pnValue = m_chrp.nDirDepth;
break;
case ktptMswMarginTop:
*pnValue = m_mpMswMarginTop;
break;
case ktptMarginTop:
*pnValue = m_mpMarginTop;
break;
case ktptMarginBottom:
*pnValue = m_mpMarginBottom;
break;
case ktptMarginLeading:
*pnValue = m_mpMarginLeading;
break;
case ktptMarginTrailing:
*pnValue = m_mpMarginTrailing;
break;
case ktptPadTop:
*pnValue = m_mpPadTop;
break;
case ktptPadBottom:
*pnValue = m_mpPadBottom;
break;
case ktptPadLeading:
*pnValue = m_mpPadLeading;
break;
case ktptPadTrailing:
*pnValue = m_mpPadTrailing;
break;
case ktptBorderTop:
*pnValue = m_mpBorderTop;
break;
case ktptBorderBottom:
*pnValue = m_mpBorderBottom;
break;
case ktptBorderLeading:
*pnValue = m_mpBorderLeading;
break;
case ktptBorderTrailing:
*pnValue = m_mpBorderTrailing;
break;
case ktptBulNumScheme:
*pnValue = m_vbnBulNumScheme;
break;
case ktptBulNumStartAt:
// *pnValue = m_nNumStartAt; WRONG! INT_MIN is not suitable for XML export!
*pnValue = m_nNumStartAt == INT_MIN ? 0 : m_nNumStartAt;
break;
case ktptForeColor:
*pnValue = m_chrp.clrFore;
break;
case ktptParaColor: // functions much like back color; kludge.
case ktptBackColor:
*pnValue = m_chrp.clrBack;
break;
case ktptBorderColor:
*pnValue = m_clrBorderColor;
break;
case ktptFirstIndent:
*pnValue = m_mpFirstIndent;
break;
case ktptLineHeight:
*pnValue = m_mpLineHeight;
break;
case ktptRelLineHeight:
*pnValue = m_nRelLineHeight;
break;
case ktptKeepWithNext:
*pnValue = m_fKeepWithNext;
break;
case ktptKeepTogether:
*pnValue = m_fKeepTogether;
break;
case ktptWidowOrphanControl:
*pnValue = m_fWidowOrphanControl;
break;
case ktptHyphenate:
*pnValue = m_fHyphenate;
break;
case ktptMaxLines:
*pnValue = m_nMaxLines;
break;
case ktptEditable:
*pnValue = m_fEditable;
break;
case ktptBaseWs:
*pnValue = m_wsBase;
break;
case ktptSpellCheck:
*pnValue = m_smSpellMode;
break;
case ktptTableRule:
return E_FAIL;
default:
StrAnsi sta;
sta.Format("invalid ID %d for reading int property", nID);
Warn(sta.Chars());
return E_NOTIMPL;
}
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
/*----------------------------------------------------------------------------------------------
Read any string property
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwPropertyStore::get_StringProperty(int nID, BSTR * bstrValue)
{
BEGIN_COM_METHOD;
ChkComOutPtr(bstrValue);
switch(nID)
{
case ktptFontFamily:
CopyBstr(bstrValue, m_stuFontFamily.Bstr());
break;
case ktptWsStyle:
CopyBstr(bstrValue, m_stuWsStyle.Bstr());
break;
case ktptFontVariations:
CopyBstr(bstrValue, m_stuFontVariations.Bstr());
break;
case ktptBulNumTxtBef:
CopyBstr(bstrValue, m_stuNumTxtBef.Bstr());
break;
case ktptBulNumTxtAft:
CopyBstr(bstrValue, m_stuNumTxtAft.Bstr());
break;
case ktptBulNumFontInfo:
CopyBstr(bstrValue, m_stuNumFontInfo.Bstr());
break;
default:
StrAnsi sta;
sta.Format("invalid ID %d for reading string property", nID);
Warn(sta.Chars());
ThrowHr(WarnHr(E_NOTIMPL));
}
END_COM_METHOD(g_factVps, IID_IVwPropertyStore);
}
//:>********************************************************************************************
//:> IVwPropertyStore Interface Methods
//:>********************************************************************************************
/*----------------------------------------------------------------------------------------------
Gets an ITsTextProps interfce pointer on a TsTextProps object whose properties are
those currently in the store. In particular, if the current VwPropertyStore has just