00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 #include "camtypes.h"
00105 #ifdef __WXGTK__
00106 #include "ftfonts.h"
00107 #endif
00108 #include "textfuns.h"
00109 #include "fontman.h"
00110
00111
00112
00113
00114
00115
00116 #include "fontimpl.h"
00117
00118
00119 DECLARE_SOURCE( "$Revision: 1642 $" );
00120
00121 CC_IMPLEMENT_DYNCREATE( FontBase, CCObject )
00122 CC_IMPLEMENT_DYNCREATE( OILFontMan, CCObject )
00123 CC_IMPLEMENT_DYNCREATE( OILEnumFonts, CCObject )
00124 CC_IMPLEMENT_MEMDUMP( FontMetricsCacheEntry, CC_CLASS_MEMDUMP );
00125 CC_IMPLEMENT_MEMDUMP( FontMetricsCache, CC_CLASS_MEMDUMP );
00126 CC_IMPLEMENT_MEMDUMP( FontKerningPairsCacheEntry, CC_CLASS_MEMDUMP );
00127 CC_IMPLEMENT_MEMDUMP( FontKerningPairsCache, CC_CLASS_MEMDUMP );
00128 CC_IMPLEMENT_MEMDUMP( CharOutlineCache, CC_CLASS_MEMDUMP );
00129
00130 #define new CAM_DEBUG_NEW
00131
00132
00133 #define IGNOREPARAM(x) x = x
00134
00136
00137 UINT32 CharOutlineCache::CacheSize = 0;
00138 DocCoord CharOutlineCache::LastMoveTo;
00139 DocCoord CharOutlineCache::CacheCoords[OILFONTLIMIT];
00140 PathVerb CharOutlineCache::CacheVerbs[OILFONTLIMIT];
00141
00142
00143 FontMetricsCacheEntry FontMetricsCache::mpFontMetricsData[FontMetricsCache::NUMENTRIES];
00144 FontKerningPairsCacheEntry FontKerningPairsCache::m_FontKerningPairsCacheData[FontKerningPairsCache::NUMENTRIES];
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 OILFontMan::OILFontMan()
00158 {
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 BOOL OILFontMan::LegalFontClass(INT32 Class, FontClass& RealClass)
00178 {
00179 BOOL ok = ((Class>((INT32)FC_UNDEFINED)) && (Class<((INT32)FC_ILLEGAL)));
00180 (ok) ? (RealClass=(FontClass)(Class)) : (RealClass=FC_UNDEFINED);
00181 return ok;
00182 }
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 BOOL OILFontMan::IsOkToCall(FontClass Class)
00200 {
00201 switch (Class)
00202 {
00203 case FC_ATM:
00204 #ifndef EXCLUDE_FROM_XARALX
00205 return ATMFontMan::IsOkToCall();
00206 #elif defined(__WXGTK__)
00207 return FTFontMan::IsOkToCall();
00208 #else
00209 return FALSE;
00210 #endif
00211 break;
00212 case FC_TRUETYPE:
00213 #ifndef EXCLUDE_FROM_XARALX
00214 return TTFontMan::IsOkToCall();
00215 #elif defined(__WXGTK__)
00216 return FTFontMan::IsOkToCall();
00217 #else
00218 return FALSE;
00219 #endif
00220 break;
00221 default:
00222 ERROR3("Unknown font class passed to OILFontMan::IsOkToCall()");
00223 break;
00224 }
00225 return FALSE;
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 BOOL OILFontMan::CacheNamedFont(String_64* pFontName, FontClass Class, INT32 Pass)
00251 {
00252
00253 switch (Pass)
00254 {
00255
00256 case 1:
00257 {
00258 switch (Class)
00259 {
00260 case FC_UNDEFINED:
00261 {
00262 #ifdef __WXGTK__
00263 if (FTFontMan::CacheNamedFont(pFontName))
00264 return TRUE;
00265 #endif
00266 PORTNOTE("text","We do not use TTFontMan in wxOil")
00267 #ifndef EXCLUDE_FROM_XARALX
00268 if (TTFontMan::CacheNamedFont(pFontName))
00269 return TRUE;
00270 #endif
00271 PORTNOTE("text","Never cache ATM font")
00272 #ifndef EXCLUDE_FROM_XARALX
00273 return ATMFontMan::CacheNamedFont(pFontName);
00274 #else
00275 return FALSE;
00276 #endif
00277 break;
00278 }
00279
00280 case FC_TRUETYPE:
00281 {
00282 #ifndef EXCLUDE_FROM_XARALX
00283 return TTFontMan::CacheNamedFont(pFontName);
00284 #elif defined(__WXGTK__)
00285 return FTFontMan::CacheNamedFont(pFontName);
00286 #else
00287 PORTNOTE("text","We do not use TTFontMan in wxOil")
00288 return FALSE;
00289 #endif
00290 break;
00291 }
00292
00293 case FC_ATM:
00294 {
00295 #ifndef EXCLUDE_FROM_XARALX
00296 return ATMFontMan::CacheNamedFont(pFontName);
00297 #elif defined(__WXGTK__)
00298 return FTFontMan::CacheNamedFont(pFontName);
00299 #else
00300 PORTNOTE("text","Never cache ATM font")
00301 return FALSE;
00302 #endif
00303 break;
00304 }
00305
00306 default:
00307 ERROR3("Unknown font class passed to OILFontMan::CacheNamedFont()");
00308 }
00309 break;
00310 }
00311
00312
00313 case 2:
00314 {
00315 switch (Class)
00316 {
00317 case FC_UNDEFINED:
00318 {
00319 #ifdef __WXGTK__
00320 if (FTFontMan::CacheCompatibleFont(pFontName))
00321 return TRUE;
00322 #endif
00323
00324 PORTNOTE("text","We do not use TTFontMan in wxOil")
00325 #ifndef EXCLUDE_FROM_XARALX
00326 if (TTFontMan::CacheCompatibleFont(pFontName))
00327 return TRUE;
00328 #endif
00329 PORTNOTE("text","Never cache ATM font")
00330 #ifndef EXCLUDE_FROM_XARALX
00331 return ATMFontMan::CacheCompatibleFont(pFontName);
00332 #else
00333 return FALSE;
00334 #endif
00335 break;
00336 }
00337
00338 case FC_TRUETYPE:
00339 {
00340 #ifndef EXCLUDE_FROM_XARALX
00341 return TTFontMan::CacheCompatibleFont(pFontName);
00342 #elif defined(__WXGTK__)
00343 return FTFontMan::CacheCompatibleFont(pFontName);
00344 #else
00345 PORTNOTE("text","We do not use TTFontMan in wxOil")
00346 return FALSE;
00347 #endif
00348 break;
00349 }
00350
00351 case FC_ATM:
00352 {
00353 #ifndef EXCLUDE_FROM_XARALX
00354 return ATMFontMan::CacheCompatibleFont(pFontName);
00355 #elif defined(__WXGTK__)
00356 return FTFontMan::CacheCompatibleFont(pFontName);
00357 #else
00358 PORTNOTE("text","Never cache ATM font")
00359 return FALSE;
00360 #endif
00361 }
00362
00363 default:
00364 ERROR3("Unknown font class passed to OILFontMan::CacheNamedFont()");
00365
00366 }
00367 break;
00368 }
00369
00370 default:
00371 ERROR3("Unknown pass selector passed to OILFontMan::CacheNamedFont()");
00372 }
00373
00374 return FALSE;
00375 }
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387 void OILFontMan::ValidateCache()
00388 {
00389 #ifdef __WXGTK__
00390 FTFontMan::ValidateCache();
00391 #endif
00392 PORTNOTE("text","We do not use TTFontMan in wxOil")
00393 #ifndef EXCLUDE_FROM_XARALX
00394 TTFontMan::ValidateCache();
00395 #endif
00396 PORTNOTE("text","ATM deactivated")
00397 #ifndef EXCLUDE_FROM_XARALX
00398 ATMFontMan::ValidateCache();
00399 #endif
00400 }
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414 void OILFontMan::FindClosestFont()
00415 {
00416 #ifdef __WXGTK__
00417 FTFontMan::FindClosestFont();
00418 #endif
00419 PORTNOTE("text","We do not use TTFontMan in wxOil")
00420 #ifndef EXCLUDE_FROM_XARALX
00421 TTFontMan::FindClosestFont();
00422 #endif
00423 PORTNOTE("text","ATM deactivated")
00424 #ifndef EXCLUDE_FROM_XARALX
00425 ATMFontMan::FindClosestFont();
00426 #endif
00427 }
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 FontBase* OILFontMan::CreateNewFont(FontClass Class, String_64* pFontName)
00444 {
00445 switch (Class)
00446 {
00447 case FC_TRUETYPE:
00448 #ifndef EXCLUDE_FROM_XARALX
00449 return TTFontMan::CreateNewFont(pFontName);
00450 #elif defined(__WXGTK__)
00451 return FTFontMan::CreateNewFont(pFontName, Class);
00452 #else
00453 PORTNOTE("text","We do not use TTFontMan in wxOil")
00454 return NULL;
00455 #endif
00456 break;
00457 case FC_ATM:
00458 #ifndef EXCLUDE_FROM_XARALX
00459 return ATMFontMan::CreateNewFont(pFontName);
00460 #elif defined(__WXGTK__)
00461 return FTFontMan::CreateNewFont(pFontName, Class);
00462 #else
00463 PORTNOTE("text","ATM deactivated")
00464 return NULL;
00465 #endif
00466 break;
00467 default:
00468 break;
00469 }
00470 ERROR3("OILFontMan::CreateNewFont() - Unknown font class");
00471 return NULL;
00472 }
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489 OUTLINETEXTMETRIC *OILFontMan::GetOutlineTextMetric(FontClass Class, LOGFONT *pLogFont)
00490 {
00491 switch (Class)
00492 {
00493 case FC_TRUETYPE:
00494 #ifndef EXCLUDE_FROM_XARALX
00495 return TTFontMan::GetOutlineTextMetric(pLogFont);
00496 #elif defined(__WXGTK__)
00497 return FTFontMan::GetOutlineTextMetric(pLogFont);
00498 #else
00499 PORTNOTE("text","TT deactivated")
00500 return NULL;
00501 #endif
00502 break;
00503 case FC_ATM:
00504 #ifndef EXCLUDE_FROM_XARALX
00505 return ATMFontMan::GetOutlineTextMetric(pLogFont);
00506 #elif defined(__WXGTK__)
00507 return FTFontMan::GetOutlineTextMetric(pLogFont);
00508 #else
00509 PORTNOTE("text","ATM deactivated")
00510 return NULL;
00511 #endif
00512 break;
00513 default:
00514 ERROR3("OILFontMan::CreateNewFont() - Unknown font class");
00515 break;
00516 }
00517 return NULL;
00518 }
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532 String_64* OILFontMan::GetNativeFontName(FontClass Class, LOGFONT *pLogFont)
00533 {
00534 IGNOREPARAM(Class);
00535 return &pLogFont->FaceName;
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546 void OILFontMan::InvalidateCharMetrics()
00547 {
00548 FontMetricsCache::InvalidateCharMetrics();
00549 }
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559 BOOL OILFontMan::GetCharMetrics(wxDC* pDC, WCHAR ch, CharDescription& FontDesc, CharMetrics* pCharMetrics)
00560 {
00561 return FontMetricsCache::GetCharMetrics(pDC, ch, FontDesc, pCharMetrics);
00562 }
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572 MILLIPOINT OILFontMan::GetCharsKerning(wxDC* pDC, WCHAR chLeft, WCHAR chRight, CharDescription& FontDesc)
00573 {
00574 return FontKerningPairsCache::GetCharsKerning(pDC, chLeft, chRight, FontDesc);
00575 }
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593 UINT32 OILFontMan::GetOutlineCache(DocCoord** pCoords, PathVerb** pVerbs)
00594 {
00595 if (pCoords!=NULL)
00596 (*pCoords)=(CharOutlineCache::CacheCoords);
00597 if (pVerbs!=NULL)
00598 (*pVerbs)=(CharOutlineCache::CacheVerbs);
00599 return (CharOutlineCache::CacheSize);
00600 }
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615 void OILFontMan::InitialiseOutlineCache()
00616 {
00617 CharOutlineCache::CacheSize=0;
00618 CharOutlineCache::LastMoveTo.x = 0x7FFFFFFF;
00619 }
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635 BOOL OILFontMan::AddMoveTo(POINT& p0)
00636 {
00637 if ((CharOutlineCache::CacheSize)<OILFONTLIMIT)
00638 {
00639 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize].x = p0.x;
00640 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize].y = p0.y;
00641 CharOutlineCache::CacheVerbs[CharOutlineCache::CacheSize] = PT_MOVETO;
00642 CharOutlineCache::CacheSize++;
00643 CharOutlineCache::LastMoveTo.x = p0.x;
00644 CharOutlineCache::LastMoveTo.y = p0.y;
00645 return TRUE;
00646 }
00647 ERROR3("CharOutlineCache overflow");
00648 return FALSE;
00649 }
00650
00651 BOOL OILFontMan::AddMoveTo(DocCoord& p0)
00652 {
00653 if ((CharOutlineCache::CacheSize)<OILFONTLIMIT)
00654 {
00655 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize] = p0;
00656 CharOutlineCache::CacheVerbs[CharOutlineCache::CacheSize] = PT_MOVETO;
00657 CharOutlineCache::CacheSize++;
00658 CharOutlineCache::LastMoveTo = p0;
00659 return TRUE;
00660 }
00661 ERROR3("CharOutlineCache overflow");
00662 return FALSE;
00663 }
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679 BOOL OILFontMan::AddLineTo(POINT& p0)
00680 {
00681 if ((CharOutlineCache::CacheSize)<OILFONTLIMIT)
00682 {
00683 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize].x = p0.x;
00684 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize].y = p0.y;
00685 CharOutlineCache::CacheVerbs[CharOutlineCache::CacheSize] = PT_LINETO;
00686 CharOutlineCache::CacheSize++;
00687 return TRUE;
00688 }
00689 ERROR3("CharOutlineCache overflow");
00690 return FALSE;
00691 }
00692
00693 BOOL OILFontMan::AddLineTo(DocCoord& p0)
00694 {
00695 if ((CharOutlineCache::CacheSize)<OILFONTLIMIT)
00696 {
00697 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize] = p0;
00698 CharOutlineCache::CacheVerbs[CharOutlineCache::CacheSize] = PT_LINETO;
00699 CharOutlineCache::CacheSize++;
00700 return TRUE;
00701 }
00702 ERROR3("CharOutlineCache overflow");
00703 return FALSE;
00704 }
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720 BOOL OILFontMan::AddBezierTo(POINT& p0, POINT& p1, POINT& p2)
00721 {
00722 if ((CharOutlineCache::CacheSize)<(OILFONTLIMIT-3))
00723 {
00724 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize].x = p0.x;
00725 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize].y = p0.y;
00726 CharOutlineCache::CacheVerbs[CharOutlineCache::CacheSize] = PT_BEZIERTO;
00727 CharOutlineCache::CacheSize++;
00728 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize].x = p1.x;
00729 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize].y = p1.y;
00730 CharOutlineCache::CacheVerbs[CharOutlineCache::CacheSize] = PT_BEZIERTO;
00731 CharOutlineCache::CacheSize++;
00732 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize].x = p2.x;
00733 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize].y = p2.y;
00734 CharOutlineCache::CacheVerbs[CharOutlineCache::CacheSize] = PT_BEZIERTO;
00735 CharOutlineCache::CacheSize++;
00736 return TRUE;
00737 }
00738 ERROR3("CharOutlineCache overflow");
00739 return FALSE;
00740 }
00741
00742 BOOL OILFontMan::AddBezierTo(DocCoord& p0, DocCoord& p1, DocCoord& p2)
00743 {
00744 if ((CharOutlineCache::CacheSize)<(OILFONTLIMIT-3))
00745 {
00746 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize] = p0;
00747 CharOutlineCache::CacheVerbs[CharOutlineCache::CacheSize] = PT_BEZIERTO;
00748 CharOutlineCache::CacheSize++;
00749 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize] = p1;
00750 CharOutlineCache::CacheVerbs[CharOutlineCache::CacheSize] = PT_BEZIERTO;
00751 CharOutlineCache::CacheSize++;
00752 CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize] = p2;
00753 CharOutlineCache::CacheVerbs[CharOutlineCache::CacheSize] = PT_BEZIERTO;
00754 CharOutlineCache::CacheSize++;
00755 return TRUE;
00756 }
00757 ERROR3("CharOutlineCache overflow");
00758 return FALSE;
00759 }
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774 BOOL OILFontMan::ClosePath()
00775 {
00776 if ((CharOutlineCache::CacheSize)<1)
00777 return FALSE;
00778
00779
00780 if (CharOutlineCache::LastMoveTo.x == 0x7FFFFFFF)
00781 {
00782 ERROR3("No moveto in outline cache");
00783 return FALSE;
00784 }
00785
00786
00787 DocCoord LastCoord = CharOutlineCache::CacheCoords[CharOutlineCache::CacheSize-1];
00788
00789
00790 if (LastCoord != CharOutlineCache::LastMoveTo)
00791 if (!AddLineTo(CharOutlineCache::LastMoveTo))
00792 return FALSE;
00793
00794
00795 CharOutlineCache::CacheVerbs[CharOutlineCache::CacheSize-1] |= PT_CLOSEFIGURE;
00796
00797 return TRUE;
00798 }
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813 void OILFontMan::FinaliseOutlineCache()
00814 {
00815 }
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837 BOOL OILFontMan::GetCharPath(FontClass fclass,
00838 CharDescription& ChDesc,
00839 DocCoord** ppCoords,
00840 PathVerb** ppVerbs,
00841 UINT32* pNumCoords,
00842 wxDC *pDC)
00843 {
00844
00845 BOOL Success=FALSE;
00846 switch (fclass)
00847 {
00848 case FC_TRUETYPE:
00849 #ifndef EXCLUDE_FROM_XARALX
00850 Success = TextManager::GetTTCharPath(ChDesc, ppCoords, ppVerbs, pNumCoords, pDC);
00851 #elif defined(__WXGTK__)
00852 Success = FTFontMan::GetCharOutline(ChDesc, ppCoords, ppVerbs, pNumCoords, pDC);
00853 #else
00854 PORTNOTE("text","TrueType deactivated")
00855 #endif
00856 ERROR1IF(Success==FALSE, FALSE, _R(IDE_FONTMAN_NOTTOUTLINE));
00857 break;
00858
00859 case FC_ATM:
00860 #ifndef EXCLUDE_FROM_XARALX
00861 Success = ATMFontMan::GetCharOutline(ChDesc, ppCoords, ppVerbs, pNumCoords, pDC);
00862 #elif defined(__WXGTK__)
00863 Success = FTFontMan::GetCharOutline(ChDesc, ppCoords, ppVerbs, pNumCoords, pDC);
00864 #else
00865 PORTNOTE("text","ATM deactivated")
00866 #endif
00867 ERROR1IF(Success==FALSE, FALSE, _R(IDE_FONTMAN_NOATMOUTLINE));
00868 break;
00869
00870 default:
00871 ERROR3("Unknown font class in OILFontMan::GetCharPath");
00872 break;
00873 }
00874 return Success;
00875 }
00876
00877
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890 FontMetricsCacheEntry::FontMetricsCacheEntry()
00891 {
00892 for (INT32 i=0; i<NUMCHARS; i++)
00893 pCharWidths[i] = 0;
00894
00895 FontEmWidth = 0;
00896 FontAscent = 0;
00897 FontDescent = 0;
00898 CharDescription emptyCharDesc(0, 0, 0, 0);
00899 FontDesc = emptyCharDesc;
00900 }
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917 BOOL FontMetricsCacheEntry::CacheFontMetrics( wxDC* pDC, CharDescription FontDesc,
00918 MILLIPOINT DefaultHeight, INT32 DesignSize )
00919 {
00920 #ifdef __WXGTK__
00921 INT32 Ascent;
00922 INT32 Descent;
00923 #endif
00924
00925
00926
00927 IGNOREPARAM(DefaultHeight);
00928 IGNOREPARAM(DesignSize);
00929
00930 #ifdef __WXGTK__
00931
00932 if (FTFontMan::GetAscentDescent(FontDesc, &Ascent, &Descent) == FALSE) return FALSE;
00933
00934 SetFontAscent( Ascent );
00935 SetFontDescent( -Descent );
00936
00937
00938 static INT32 pTempCharWidthBuf[NUMCHARS];
00939 if (FTFontMan::GetCharWidth(FontDesc, FIRSTCHAR, LASTCHAR, pTempCharWidthBuf)==FALSE)
00940 return FALSE;
00941
00942 for (INT32 i=0; i<NUMCHARS; i++)
00943 pCharWidths[i] = pTempCharWidthBuf[i];
00944
00945
00946 if (CharInCacheRange(FONTEMCHAR))
00947 SetFontEmWidth( GetCharWidthFromCache(FONTEMCHAR) );
00948 else
00949 {
00950 ERROR3("FontMetricsCache::GetCharMetrics() - 'FONTEMCHAR' not in cache!");
00951 INT32 TempCharWidth = 0;
00952 if (FTFontMan::GetCharWidth(FontDesc, FONTEMCHAR, FONTEMCHAR, &TempCharWidth)==FALSE)
00953 return FALSE;
00954
00955 SetFontEmWidth( TempCharWidth );
00956 }
00957
00958
00959 SetFontDesc(FontDesc);
00960 #else // !wxGTK
00961 return FALSE;
00962 #endif
00963
00964 #ifndef EXCLUDE_FROM_XARALX
00965
00966 CheckCharWidthsSameAsABCWidths(pDC,FontDesc);
00967 #endif
00968 return TRUE;
00969 }
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982 void FontMetricsCacheEntry::CheckCharWidthsSameAsABCWidths(wxDC* pDC, CharDescription FontDesc)
00983 {
00984 #ifdef _DEBUG
00985 #ifndef EXCLUDE_FROM_XARALX
00986
00987
00988
00989 CachedFontItem* pItem = FONTMANAGER->GetFont(FontDesc.GetTypefaceHandle());
00990 if (pItem->GetFontClass()==FC_ATM || pItem==NULL || pItem->IsCorrupt())
00991 return;
00992
00993 INT32 pTempCharWidthBuf[NUMCHARS];
00994 ABC pTempCharABCBuf[NUMCHARS];
00995 BOOL ok = TextManager::GetCharWidth( pDC, FIRSTCHAR, LASTCHAR, pTempCharWidthBuf);
00996 if (ok) ok = TextManager::GetCharABCWidths(pDC, FIRSTCHAR, LASTCHAR, pTempCharABCBuf);
00997 ERROR3IF(!ok,"FontMetricsCache::CheckCharWidthsSameAsABCWidths() - TextManager::GetCharWidth()/GetCharABCWidths() failed!\n");
00998
00999 for (INT32 i=0; i<NUMCHARS; i++)
01000 {
01001 ABC* pABC = &pTempCharABCBuf[i];
01002 INT32 SumABC = pABC->abcA+pABC->abcB+pABC->abcC;
01003 INT32 CharWidth = pTempCharWidthBuf[i];
01004 ERROR3IF_PF(SumABC!=CharWidth,("FontMetricsCache::CheckCharWidthsSameAsABCWidths() - sum of ABCwidths (%d) differs from CharWidths (%d)",SumABC,CharWidth));
01005 }
01006 #endif
01007
01008
01009 #if 0
01010
01011
01012 INT32 DesignSizeInPixels = TextManager::GetDesignSize(pDC);
01013 INT32 DefaultSizeInMP = TextManager::GetDefaultHeight();
01014 INT32 dpi = pDC->GetDeviceCaps(LOGPIXELSY);
01015 for (MILLIPOINT FontSizeInMP=4000; FontSizeInMP<=72000; FontSizeInMP+=4000)
01016 {
01017 double SumNewMetrics = 0;
01018 double SumOldMetrics = 0;
01019 double SumAccurateMetrics = 0;
01020 for (WCHAR ch=0; ch<256; ch++)
01021 {
01022 INT32 DesignSizeMetricInPixels = 500;
01023 BOOL ok = TextManager::GetCharWidth(pDC,ch,ch,&DesignSizeMetricInPixels);
01024 ERROR3IF(!ok,"FontMetricsCache::CheckCharWidthsSameAsABCWidths() - TextManager::GetCharWidth() failed!\n");
01025
01026
01027 MILLIPOINT InchMetricInMP = MulDiv(DesignSizeMetricInPixels, DefaultSizeInMP, DesignSizeInPixels);
01028 FIXED16 InchMetricToFontSizeMetricRatio = Div32By32(FontSizeInMP, DefaultSizeInMP);
01029 MILLIPOINT NewFontSizeMetricInMP = InchMetricInMP * InchMetricToFontSizeMetricRatio;
01030 SumNewMetrics += NewFontSizeMetricInMP;
01031
01032
01033 MILLIPOINT DesignSizeMetricInMP = MulDiv(DesignSizeMetricInPixels, 72000, dpi);
01034 MILLIPOINT DesignSizeInMP = MulDiv(DesignSizeInPixels, 72000, dpi);
01035 FIXED16 DesignSizeMetricToFontSizeMetricRatio = Div32By32(FontSizeInMP, DesignSizeInMP);
01036 MILLIPOINT OldFontSizeMetricInMP = DesignSizeMetricInMP * DesignSizeMetricToFontSizeMetricRatio;
01037 SumOldMetrics += OldFontSizeMetricInMP;
01038
01039
01040 double AccurateFontSizeMetricInMP = (double) DesignSizeMetricInPixels / DesignSizeInPixels * FontSizeInMP;
01041 SumAccurateMetrics += AccurateFontSizeMetricInMP;
01042 }
01043 TRACEUSER( "Ed", _T("Sum of CharWidths (%5dMP): new=%8.0f (e=%6.2f), old=%8.0f (e=%6.2f), accrutate=%8.2f\n"), FontSizeInMP, SumNewMetrics, SumNewMetrics-SumAccurateMetrics, SumOldMetrics, SumOldMetrics-SumAccurateMetrics, SumAccurateMetrics);
01044 }
01045 #endif // EXCLUDE_FROM_XARALX
01046 #endif // _DEBUG
01047 }
01048
01049
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068 BOOL FontMetricsCache::GetCharMetrics(wxDC* pDC, WCHAR ch, CharDescription& FontDesc, CharMetrics* pCharMetrics)
01069 {
01070
01071 IGNOREPARAM(pDC);
01072 ERROR2IF(pCharMetrics==NULL,FALSE,"FontMetricsCache::GetCharMetrics() - pCharMetrics==NULL");
01073 ERROR2IF(FontDesc.GetCharCode()!=FONTEMCHAR,FALSE,"FontMetricsCache::GetCharMetrics() - FontDesc char should be 'FONTEMCHAR'");
01074
01075
01076 INT32 CacheEntry = 0;
01077 while (CacheEntry<NUMENTRIES && mpFontMetricsData[CacheEntry].GetFontDesc()!=FontDesc)
01078 CacheEntry +=1;
01079
01080
01081 MILLIPOINT CharWidth = 0;
01082 BOOL CharInCacheRange = FontMetricsCacheEntry::CharInCacheRange(ch);
01083 if (CacheEntry>=NUMENTRIES || !CharInCacheRange)
01084 {
01085
01086 INT32 DesignSize = TextManager::GetDesignSize(pDC);
01087 INT32 DefaultHeight = TextManager::GetDefaultHeight();
01088
01089 CachedFontItem* pItem = FONTMANAGER->GetFont(FontDesc.GetTypefaceHandle());
01090 if (pItem==NULL || pItem->IsCorrupt())
01091 return FALSE;
01092
01093
01094 LOGFONT CharLogFont;
01095 if (TextManager::GetLogFontFromCharDescriptor(pDC, FontDesc, &CharLogFont, DesignSize)==FALSE)
01096 return FALSE;
01097
01098
01099 if (CacheEntry>=NUMENTRIES)
01100 {
01101 CacheEntry = rand() % NUMENTRIES;
01102 if (mpFontMetricsData[CacheEntry].CacheFontMetrics(pDC, FontDesc, DefaultHeight, DesignSize) == FALSE)
01103 return FALSE;
01104 }
01105
01106
01107 if (!CharInCacheRange)
01108 {
01109 if (ch==FONTEMCHAR)
01110 CharWidth = mpFontMetricsData[CacheEntry].GetFontEmWidth();
01111 else
01112 {
01113 #ifdef __WXGTK__
01114
01115 if (FTFontMan::GetCharWidth(FontDesc, ch, ch, &CharWidth)==FALSE)
01116 #endif
01117 return FALSE;
01118 }
01119 }
01120 }
01121
01122 if (CharInCacheRange)
01123 CharWidth = mpFontMetricsData[CacheEntry].GetCharWidthFromCache(ch);
01124
01125 pCharMetrics->CharWidth = CharWidth;
01126 pCharMetrics->FontAscent = mpFontMetricsData[CacheEntry].GetFontAscent();
01127 pCharMetrics->FontEmWidth = mpFontMetricsData[CacheEntry].GetFontEmWidth();
01128 pCharMetrics->FontDescent = mpFontMetricsData[CacheEntry].GetFontDescent();
01129 return TRUE;
01130 }
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141 void FontMetricsCache::InvalidateCharMetrics()
01142 {
01143 CharDescription emptyCharDesc(0, 0, 0, 0);
01144 for (INT32 i=0; i<NUMENTRIES; i++)
01145 mpFontMetricsData[i].SetFontDesc( emptyCharDesc );
01146 }
01147
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166 MILLIPOINT FontKerningPairsCache::GetCharsKerning(wxDC* pDC, WCHAR chLeft, WCHAR chRight,
01167 CharDescription& FontDesc)
01168 {
01169
01170 ERROR2IF(pDC==NULL, 0, "FontKerningPairsCache::GetCharsKerning() - pDC==NULL");
01171 ERROR2IF(FontDesc.GetCharCode() != FONTEMCHAR, FALSE,
01172 "FontKerningPairsCache::GetCharsKerning() - FontDesc char should be 'FONTEMCHAR'");
01173 #ifndef DISABLE_TEXT_RENDERING
01174
01175 INT32 CacheEntry = 0;
01176 while (CacheEntry < NUMENTRIES && m_FontKerningPairsCacheData[CacheEntry].GetFontDesc() != FontDesc)
01177 CacheEntry++;
01178
01179 if (CacheEntry >= NUMENTRIES)
01180 {
01181
01182
01183
01184 CacheEntry = rand() % NUMENTRIES;
01185 m_FontKerningPairsCacheData[CacheEntry].Reinitialise(FontDesc);
01186 }
01187 return m_FontKerningPairsCacheData[CacheEntry].GetCharsKerning(chLeft, chRight);
01188 #else
01189 return 0;
01190 #endif
01191 }
01192
01193 #ifdef _DEBUG
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203 void FontKerningPairsCache::Dump()
01204 {
01205 TRACE( _T(">>> Font kerning data start >>>\n"));
01206 for (INT32 i=0; i<NUMENTRIES; ++i)
01207 {
01208 TRACE( _T("Entry %d:\n"), i);
01209 m_FontKerningPairsCacheData[i].Dump();
01210 }
01211 TRACE( _T("<<< Font kerning data end <<<\n"));
01212 }
01213 #endif // _DEBUG
01214
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226 FontKerningPairsCacheEntry::FontKerningPairsCacheEntry()
01227 {
01228 CharDescription emptyCharDesc(0, 0, 0, 0);
01229 FontDesc = emptyCharDesc;
01230 m_pPairsCacheMap = NULL;
01231 }
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241 FontKerningPairsCacheEntry::~FontKerningPairsCacheEntry()
01242 {
01243 if (m_pPairsCacheMap) delete m_pPairsCacheMap;
01244 }
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256 void FontKerningPairsCacheEntry::Reinitialise(CharDescription& NewFontDesc)
01257 {
01258 FontDesc = NewFontDesc;
01259 if (m_pPairsCacheMap) delete m_pPairsCacheMap;
01260 m_pPairsCacheMap = new std::map<UINT32,INT32>;
01261
01262
01263 }
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278 MILLIPOINT FontKerningPairsCacheEntry::GetCharsKerning(WCHAR chLeft, WCHAR chRight)
01279 {
01280 UINT32 key;
01281
01282
01283 if (chLeft > 0x10000 || chRight > 0x10000 || m_pPairsCacheMap == NULL)
01284 {
01285
01286 #ifdef __WXGTK__
01287 return FTFontMan::GetCharsKerning(FontDesc, chLeft, chRight);
01288 #else
01289 return 0;
01290 #endif
01291 }
01292
01293 key = (chLeft << 16) | chRight;
01294 std::map<UINT32,INT32>::iterator it = m_pPairsCacheMap->find(key);
01295 if (it != m_pPairsCacheMap->end()) {
01296
01297
01298 return it->second;
01299 }
01300 else {
01301
01302 #ifdef __WXGTK__
01303 INT32 kerning = FTFontMan::GetCharsKerning(FontDesc, chLeft, chRight);
01304 #else
01305 INT32 kerning = 0;
01306 #endif
01307
01308
01309 (*m_pPairsCacheMap)[key] = kerning;
01310 return kerning;
01311 }
01312 }
01313
01314 #if _DEBUG
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325 void FontKerningPairsCacheEntry::Dump()
01326 {
01327
01328 if (m_pPairsCacheMap != NULL) {
01329 for (std::map<UINT32,INT32>::iterator it = m_pPairsCacheMap->begin(); it != m_pPairsCacheMap->end(); ++it)
01330 {
01331 UINT32 key = (*it).first;
01332 TRACE(_T("cached kern pair %04x/%04x = %d"), key >> 16, key & 0xffff, (*it).second);
01333 }
01334 }
01335 }
01336
01337 #endif // _DEBUG
01338
01340
01341
01342
01343 #if _DEBUG
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355 void CharOutlineCache::Dump()
01356 {
01357 UINT32 i=0;
01358
01359 TRACE( _T("CHAROUTLINECACHE DUMP\n"));
01360
01361 while (i < CacheSize)
01362 {
01363 switch ((CacheVerbs[i]) & ~PT_CLOSEFIGURE)
01364 {
01365 case PT_MOVETO:
01366 TRACE( _T("MoveTo "));
01367 TRACE( _T("(%d,"),CacheCoords[i].x);
01368 TRACE( _T("%d)\n"),CacheCoords[i].y);
01369 i++;
01370 break;
01371 case PT_LINETO:
01372 TRACE( _T("LineTo "));
01373 TRACE( _T("(%d,"),CacheCoords[i].x);
01374 TRACE( _T("%d)\n"),CacheCoords[i].y);
01375 i++;
01376 break;
01377 case PT_BEZIERTO:
01378 TRACE( _T("CurveTo "));
01379 TRACE( _T("(%d,"),CacheCoords[i].x);
01380 TRACE( _T("%d) "),CacheCoords[i].y);
01381 TRACE( _T("(%d,"),CacheCoords[i+1].x);
01382 TRACE( _T("%d) "),CacheCoords[i+1].y);
01383 TRACE( _T("(%d,"),CacheCoords[i+2].x);
01384 TRACE( _T("%d)\n"),CacheCoords[i+2].y);
01385 i+=3;
01386 break;
01387 }
01388 }
01389 }
01390
01391 #endif
01392
01393 #if _DEBUG
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405 void OILFontMan::DumpEnumLogFont(ENUMLOGFONT* lpelf)
01406 {
01407 TRACE( _T("DumpELogFont at %ld\n"),lpelf);
01408 if (lpelf!=NULL)
01409 {
01410 TRACE( _T(" ---------------- \n"));
01411 TRACE( _T("Enum Log font structure:\n"));
01412 #ifndef EXCLUDE_FROM_XARALX
01413 TRACE( _T(" Full name = %s\n"), lpelf->elfFullName);
01414 TRACE( _T(" Style = %s\n"), lpelf->elfStyle);
01415 #endif
01416 DumpLogFont(&(lpelf->elfLogFont));
01417 TRACE( _T(" ---------------- \n"));
01418 }
01419 }
01420
01421 void OILFontMan::DumpLogFont(LOGFONT* lplf)
01422 {
01423 if (lplf!=NULL)
01424 {
01425 TRACE( _T("Log font structure:\n"));
01426 #ifndef EXCLUDE_FROM_XARALX
01427 TRACE( _T(" Height = %d\n"), lplf->lfHeight);
01428 TRACE( _T(" Width = %d\n"), lplf->lfWidth);
01429 TRACE( _T(" Escapement = %d\n"), lplf->lfEscapement);
01430 TRACE( _T(" Orientation = %d\n"), lplf->lfOrientation);
01431 TRACE( _T(" Weight = %d\n"), lplf->lfWeight);
01432 TRACE( _T(" Italic = %d\n"), lplf->lfItalic);
01433 TRACE( _T(" Underline = %d\n"), lplf->lfUnderline);
01434 TRACE( _T(" StrikeOut = %d\n"), lplf->lfStrikeOut);
01435 TRACE( _T(" CharSet = %d\n"), lplf->lfCharSet);
01436 TRACE( _T(" OutPrecision = %d\n"), lplf->lfOutPrecision);
01437 TRACE( _T(" ClipPrecision = %d\n"), lplf->lfClipPrecision);
01438 TRACE( _T(" Quality = %d\n"), lplf->lfQuality);
01439 TRACE( _T(" PitchAndFamily = %d\n"), lplf->lfPitchAndFamily);
01440 TRACE( _T(" FaceName = %s\n"), lplf->lfFaceName);
01441 #endif
01442 }
01443 }
01444
01445 #endif
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460 FontBase::FontBase()
01461 {
01462 }
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476 BOOL FontBase::Initialise(String_64 *pFontName)
01477 {
01478 TheFontName = *pFontName;
01479 return TRUE;
01480 }
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495 void FontBase::Delete()
01496 {
01497 ERROR3("Error Error, FontBase::Delete() called - bad derivation / v-table corrupted");
01498 }
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514 BOOL FontBase::Compare(String_64* pFontName)
01515 {
01516 return ((TheFontName.CompareTo(*pFontName)) == 0);
01517 }
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533 void FontBase::Dump()
01534 {
01535 TRACE( _T(" Font name = %s\n"),((TCHAR*)TheFontName));
01536 }
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552 OILEnumFonts::OILEnumFonts()
01553 {
01554 }
01555
01556 void OILEnumFonts::Execute()
01557 {
01558 PORTNOTE("text","We do not use TTFontMan in wxOil")
01559 #ifndef EXCLUDE_FROM_XARALX
01560 TTFontMan::EnumAllFonts(this);
01561 #endif
01562 PORTNOTE("text","We do not use ATMFontMan in wxOil")
01563 #ifndef EXCLUDE_FROM_XARALX
01564 ATMFontMan::EnumAllFonts(this);
01565 #endif
01566 #ifdef __WXGTK__
01567 FTFontMan::EnumAllFonts(this);
01568 #endif
01569
01570 }
01571
01572
01573 BOOL OILEnumFonts::NewFont(FontClass Class, ENUMLOGFONT *lpelf)
01574 {
01575 return FALSE;
01576 }