Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

471 lines
16 KiB

  1. /******************************************************************************
  2. Header File: Generic Font Information.H
  3. This file contains a set of classes intended to incorporate the information
  4. currently stored in the various font metric and related structures. These
  5. classes are serializable, and will be capable of being loaded from and fed to
  6. the various other formats.
  7. Copyright (c) 1997 by Microsoft Corporation. All Rights Reserved.
  8. A Pretty Penny Enterprises Production
  9. Change History:
  10. 03-02-1997 Bob_Kjelgaard@Prodigy.Net Created it
  11. ******************************************************************************/
  12. #if !defined(GENERIC_FONT_INFORMATION)
  13. #define GENERIC_FONT_INFORMATION
  14. #include "GTT.H"
  15. #include "CodePage.H"
  16. #include "resource.h"
  17. #include "Llist.h"
  18. /*
  19. // These are used to glue in UFM-specific stuff
  20. struct INVOCATION {
  21. DWORD dwcbCommand; // Byte size of string
  22. DWORD dwofCommand; // Offset in the file to the string
  23. };
  24. */
  25. // `Yes, this is a bit sleazy, but DirectDraw has nothing now or ever to
  26. // do with this tool, so why waste time tracking down more files?
  27. /*
  28. #define __DD_INCLUDED__
  29. typedef DWORD PDD_DIRECTDRAW_GLOBAL, PDD_SURFACE_LOCAL, DESIGNVECTOR,
  30. DD_CALLBACKS, DD_HALINFO,
  31. DD_SURFACECALLBACKS, DD_PALETTECALLBACKS, VIDEOMEMORY;
  32. */
  33. //#define INVOCATION int
  34. #define DESIGNVECTOR int // We need lots of stuff from winddi.h and fmnewfm.h,
  35. // but the compiler whines, so I will cheat and provide a bogus
  36. #include "winddi.h" // definition for DESIGNVECTOR, which we never use anyway, so it's
  37. #include "fmnewfm.h" // okay, right? What a hack!
  38. #include <math.h>
  39. /******************************************************************************
  40. CFontDifference
  41. This class handles the information content analogous to the FONTDIFF
  42. structure.
  43. ******************************************************************************/
  44. class CFontDifference
  45. {
  46. CWordArray m_cwaMetrics;
  47. CBasicNode *m_pcbnOwner;
  48. public:
  49. CFontDifference(WORD wWeight, WORD wMax, WORD wAverage, WORD wAngle, CBasicNode *pcbn)
  50. {
  51. m_cwaMetrics.Add(wWeight);
  52. m_cwaMetrics.Add(wMax);
  53. m_cwaMetrics.Add(wAverage);
  54. m_cwaMetrics.Add(wAngle);
  55. m_pcbnOwner = pcbn;
  56. }
  57. CFontDifference(PBYTE pb, CBasicNode *pcbn); // Init from memory image
  58. // Attributes
  59. enum {Weight, Max, Average, Angle};
  60. WORD Metric(unsigned u)
  61. {
  62. int bob = 5;
  63. return m_cwaMetrics[u];
  64. }
  65. // operations
  66. enum {OK, TooBig, Reversed}; // Returns from SetMetric
  67. WORD SetMetric(unsigned u, WORD wNew);
  68. void Store(CFile& cfStore, WORD wfSelection);
  69. CWordArray* GetFontSimDataPtr() { return &m_cwaMetrics ; }
  70. };
  71. /******************************************************************************
  72. CFontInfo class
  73. This primarily encapsulates the UFM file, but it also has to handle some PFM
  74. and IF stuff, so it truly is generic.
  75. ******************************************************************************/
  76. class CFontInfo : public CProjectNode
  77. {
  78. // True iff the font was loaded by the workspace OR the font was loaded
  79. // directly AND its GTT/CP was found and loaded.
  80. bool m_bLoadedByWorkspace ;
  81. // The flag above has many uses now so another flag is needed. This flag
  82. // is only set when the UFM is being loaded by a workspace and no GTT/CP
  83. // could be loaded for it.
  84. bool m_bWSLoadButNoGTTCP ;
  85. //DWORD m_loWidthTable ; // Width table offset from UFM file. Used as
  86. // part of variable font determination.
  87. public:
  88. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  89. // UNIFM_HDR
  90. ULONG m_ulDefaultCodepage;
  91. WORD m_lGlyphSetDataRCID; // Translation table ID // rm new
  92. const WORD Translation() const { return m_lGlyphSetDataRCID; } // rm new
  93. void SetTranslation(WORD w) { m_lGlyphSetDataRCID = w; } // rm new
  94. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  95. UNIDRVINFO m_UNIDRVINFO; // UNIDRVINFO // rm new
  96. BOOL m_fScalable;
  97. CInvocation m_ciSelect, m_ciDeselect; // rm moved from below
  98. CInvocation& Selector(BOOL bSelect = TRUE)
  99. { return bSelect ? m_ciSelect : m_ciDeselect; } // rm moved from below
  100. CString GTTDescription() const;
  101. // IFIMETRICS //////////////////////////////////////////////// ////////////
  102. private:
  103. CString& Family(unsigned u) { return m_csaFamily[u]; }
  104. public:
  105. IFIMETRICS m_IFIMETRICS; // rm new
  106. WORD SetSignificant(WORD wItem, WORD wChar, BOOL bUnicode);
  107. enum {Default, Break}; // Used to set the wcDefaultChar, wcBreakChar,
  108. // chDefaultChar, and chBreakChar.
  109. enum {OK, InvalidChar, DoubleByte}; // Return values for SetSignificant(WORD wItem, WORD wChar, BOOL bUnicode)
  110. WORD m_InternalLeading;
  111. WORD m_Lowerd;
  112. WORD m_Lowerp;
  113. WORD m_ItalicAngle;
  114. CStringArray m_csaFamily;
  115. CString m_csStyle, m_csFace, m_csUnique; // Various names
  116. CWordArray m_cwaSpecial; // Special, little-used metrics
  117. //BYTE m_bCharacterSet, m_bPitchAndFamily; // rm no longer needede
  118. WORD m_wWeight, m_wHeight;
  119. //WORD m_wAverageWidth, m_wMaximumIncrement, m_wfStyle; // rm no longer needede
  120. //CByteArray m_cbaSignificant; // Significant char codes (e.g., break)
  121. //CWordArray m_cwaSignificant; // rm absorbed into m_IFIMETRICS
  122. // const CString& StyleName() const { return m_csStyle; }
  123. // const CString& FaceName() const { return m_csFace; }
  124. // const CString& UniqueName() const { return m_csUnique; }
  125. unsigned Families() const { return (unsigned) m_csaFamily.GetSize(); }
  126. // void SetStyleName(LPCTSTR lpstrNew) { m_csStyle = lpstrNew; Changed(); }
  127. // void SetFaceName(LPCTSTR lpstrNew) { m_csFace = lpstrNew; Changed(); }
  128. void SetUniqueName(LPCTSTR lpstrNew) { m_csUnique = lpstrNew; Changed(); } // used by rcfile.cpp
  129. BOOL AddFamily(LPCTSTR lpstrNew);
  130. void RemoveFamily(LPCTSTR lpstrDead);
  131. // WORD Family() const { return m_bPitchAndFamily & 0xF0; } // rm no longer needed
  132. // WORD CharSet() const { return m_bCharacterSet; } // rm no longer needed
  133. // WORD Weight() const { return m_wWeight; } // rm no longer needed
  134. WORD Height() const { return m_wHeight; }
  135. // WORD MaxWidth() const { return m_wMaximumIncrement; } // rm no longer needed
  136. // WORD AverageWidth() const { return m_wAverageWidth; } // rm no longer needed
  137. // enum {Old_First, Last, Default, Break};
  138. // WORD SignificantChar(WORD wid, BOOL bUnicode = TRUE) const // rm no longer needed
  139. // { return bUnicode ? m_cwaSignificant[wid] : m_cbaSignificant[wid]; }
  140. // void InterceptItalic(CPoint& cpt) const; // rm no longer needed
  141. // void SetFamily(BYTE bNew) { m_bPitchAndFamily &= 0xF; m_bPitchAndFamily |= (bNew & 0xF0); // rm no longer needed
  142. // Changed(); }
  143. BOOL SetCharacterSet(BYTE bNew);
  144. // void SetWeight(WORD wWeight) { m_wWeight = wWeight; Changed(); } // rm no longer needed
  145. BOOL SetHeight(WORD wHeight);
  146. void SetMaxWidth(WORD wWidth);
  147. void SetSpecial(unsigned ufMetric, short sSpecial);
  148. enum {Italic = 1, Underscore, StrikeOut = 0x10};
  149. void ChangePitch(BOOL bFixed = FALSE);
  150. enum { CapH, LowerX, SuperSizeX, SuperSizeY, //
  151. SubSizeX, SubSizeY, SuperMoveX, SuperMoveY,
  152. SubMoveX, SubMoveY, ItalicAngle, UnderSize,
  153. UnderOffset, StrikeSize, StrikeOffset,
  154. oldBaseline,
  155. /*Baseline, */ InterlineGap, Lowerp, Lowerd,
  156. InternalLeading};
  157. const short SpecialMetric(unsigned uIndex) const { return (short) m_cwaSpecial[uIndex]; }
  158. BOOL DBCSFont() const // rm new
  159. { return m_IFIMETRICS.jWinCharSet > 127 && m_IFIMETRICS.jWinCharSet < 145; } // This looks right, but no OFFICIAL way seems to exist
  160. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  161. // FONT SIMULATIONS
  162. CFontDifference *m_pcfdBold, *m_pcfdItalic, *m_pcfdBoth; // Simulations
  163. enum {ItalicDiff, BoldDiff, BothDiff};
  164. // CFontDifference *Diff(unsigned u) { return u ? u == BothDiff ? m_pcfdBoth : m_pcfdBold : m_pcfdItalic; }
  165. CFontDifference * Diff(unsigned u)
  166. {
  167. CFontDifference * FontDiff = m_pcfdBold; // preset return value
  168. if (!u) FontDiff = m_pcfdItalic;
  169. if (u == BothDiff) FontDiff = m_pcfdBoth;
  170. return FontDiff;
  171. }
  172. void EnableSim(unsigned uSim, BOOL bOn, CFontDifference * & pcfd);
  173. CWordArray* GetFontSimDataPtr(int nid) ;
  174. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  175. EXTTEXTMETRIC m_EXTTEXTMETRIC; // EXTTEXTMETRIC structure
  176. BOOL m_fEXTTEXTMETRIC; // rm new
  177. BOOL m_fSave_EXT;
  178. WORD m_wMaxScale, m_wMinScale, m_wScaleDevice;
  179. //BYTE m_bfScaleOrientation;
  180. // BYTE ScaleOrientation() const
  181. // { return m_bfScaleOrientation & 3; }
  182. WORD ScaleUnits(BOOL bDevice = TRUE) const
  183. { return bDevice ? m_wScaleDevice : m_wHeight - m_InternalLeading; } // m _cwaSpecial[InternalLeading];
  184. WORD ScaleLimit(BOOL bMaximum = TRUE) const
  185. { return bMaximum ? m_wMaxScale : m_wMinScale; }
  186. enum {ScaleOK, Reversed, NotWindowed};
  187. WORD SetScaleLimit(BOOL bMax, WORD wNew);
  188. WORD SetDeviceEmHeight(WORD wNew);
  189. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  190. // FRAMEWORK OPERATIONS
  191. CString m_csSource; // The original PFM file name
  192. CByteArray m_cbaPFM; // Loaded image of the PFM file
  193. BOOL MapPFM(); // Assure the PFM file is loaded
  194. DECLARE_SERIAL(CFontInfo)
  195. public:
  196. void SetRCIDChanged(bool bFlags) { m_bRCIDChanged = bFlags ; } ;
  197. bool IsRCIDChanged() {return m_bRCIDChanged ; } ;
  198. CLinkedList* CompareGlyphsEx(WORD wOld, WORD wNew, CLinkedList* pcll);
  199. CFontInfo();
  200. CFontInfo(const CFontInfo& cfiRef, WORD widCTT); // For cloning of UFMs
  201. ~CFontInfo();
  202. BOOL Load(bool bloadedbyworkspace = false); // Load the UFM file so it can be edited
  203. BOOL Store(LPCTSTR lpstrFileName, BOOL bStoreFromWorkspace = FALSE); // raid 244123 // Save as the specified UFM file
  204. BOOL StoreGTTCPOnly(LPCTSTR lpstrFileName); // Save the UFM's GTT and CP fields
  205. virtual CMDIChildWnd* CreateEditor();
  206. virtual void Serialize(CArchive& car);
  207. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  208. // ATTRIBUTES - CONVERSION SUPPORT
  209. const CString& SourceName() const { return m_csSource; }
  210. void SetSourceName(LPCTSTR lpstrNew);
  211. BOOL SetFileName(LPCTSTR lpstrNew) ;
  212. int GetTranslation(CSafeObArray& csoagtts);
  213. //int GetTranslation();
  214. int Generate(CString csPath);
  215. // void SetTranslation(WORD w) { m_widTranslation = w; } // rm ori - moved to new section
  216. void SetTranslation(CGlyphMap* pcgm) { m_pcgmTranslation = pcgm; }
  217. // The following functions return the character range for the mapping table
  218. // in the UFM's corresponding GTT. These are needed when a GTT needs to be
  219. // built for the UFM.
  220. WORD GetFirst() { return ((WORD) m_IFIMETRICS.chFirstChar) ; }
  221. WORD GetLast() { return ((WORD) m_IFIMETRICS.chLastChar) ; }
  222. WORD GetFirstPFM() ;
  223. WORD GetLastPFM() ;
  224. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  225. // CHARACTER WIDTHS PAGE
  226. CGlyphMap* m_pcgmTranslation;
  227. CPtrArray m_cpaGlyphs;
  228. CPtrArray m_cpaOldGlyphs;
  229. CWordArray m_cwaOldGlyphs ;
  230. CWordArray m_cwaNewGlyphs ;
  231. CWordArray m_cwaWidth;
  232. CTime m_ctReloadWidthsTimeStamp ; // The last time width info was reloaded
  233. CGlyphHandle& Glyph(unsigned uid)
  234. {return *(CGlyphHandle *) m_cpaGlyphs[uid];}
  235. //BOOL IsVariableWidth() const
  236. // { return (m_loWidthTable || (m_IFIMETRICS.jWinPitchAndFamily & 2)) ; }
  237. BOOL IsVariableWidth() const
  238. { return !!m_cpaGlyphs.GetSize(); } // When variable widths change...
  239. void CalculateWidths();
  240. bool CheckReloadWidths() ;
  241. enum {Less, More, Equal};
  242. unsigned CompareWidths(unsigned u1, unsigned u2);
  243. void FillWidths(CListCtrl& clcView); // Fill the control
  244. void SetWidth(unsigned uGlyph, WORD wWidth, bool bcalc = true);
  245. bool WidthsTableIsOK() ;
  246. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  247. // KERNING PAGE
  248. // Kerning structure- CSafeObArray which contains the kerning pairs. Also,
  249. // a copy of m_csoaKern used during editing to make sure m_csoaKern isn't
  250. // permanently changed without user ok.
  251. CSafeObArray m_csoaKern ;
  252. CSafeObArray m_csoaKernCopy ;
  253. BOOL CanKern() const { return !!m_csoaKern.GetSize(); }
  254. void MapKerning(CSafeMapWordToOb& csmw2o1,
  255. CSafeMapWordToOb& csmw2o2,
  256. CWordArray& cwaPoints);
  257. unsigned KernCount() const { return (unsigned) m_csoaKern.GetSize(); }
  258. unsigned CompareKernAmount(unsigned u1, unsigned u2) const;
  259. unsigned CompareKernFirst (unsigned u1, unsigned u2) const;
  260. unsigned CompareKernSecond(unsigned u1, unsigned u2) const;
  261. WCHAR GetKernFirst(unsigned u) const ;
  262. WCHAR GetKernSecond(unsigned u) const ;
  263. short GetKernAmount(unsigned u) const ;
  264. void FillKern(CListCtrl& clcView); // Fill the control
  265. void AddKern(WORD wFirst, WORD wSecond, short sAmount, CListCtrl& clcView);
  266. void RemoveKern(unsigned u) { m_csoaKern.RemoveAt(u); Changed(); }
  267. void SetKernAmount(unsigned u, short sAmount);
  268. void MakeKernCopy() ;
  269. bool LoadBadKerningInfo(CListCtrl& clcbaddata) ;
  270. bool CodePointInGTT(WORD wcodepoint) ;
  271. void SetNoGTTCP(bool bval) { m_bWSLoadButNoGTTCP = bval ; }
  272. private:
  273. bool m_bRCIDChanged;
  274. bool FindAndLoadGTT();
  275. };
  276. /******************************************************************************
  277. CFontInfoContainer class
  278. This CDocument-derived class contains one CFontInfo structure- it allows to
  279. edit the font information either from the driver, os from an individual file.
  280. ******************************************************************************/
  281. class CFontInfoContainer : public CDocument
  282. {
  283. CFontInfo *m_pcfi;
  284. bool m_UFMSaved ; // True iff an attempt to save the associated
  285. // UFM was just made.
  286. protected:
  287. CFontInfoContainer(); // protected constructor used by dynamic creation
  288. DECLARE_DYNCREATE(CFontInfoContainer)
  289. // Attributes
  290. public:
  291. BOOL m_bEmbedded; // UFM loaded from workspace
  292. CFontInfo *Font() { return m_pcfi; }
  293. // Operations
  294. public:
  295. // First a constructor for launching a view from the driver view.
  296. CFontInfoContainer(CFontInfo *pcfi, CString csPath);
  297. BOOL PublicSaveModified();
  298. // Overrides
  299. // ClassWizard generated virtual function overrides
  300. //{{AFX_VIRTUAL(CFontInfoContainer)
  301. public:
  302. virtual void Serialize(CArchive& ar); // overridden for document i/o
  303. virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
  304. virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
  305. protected:
  306. virtual BOOL OnNewDocument();
  307. virtual BOOL SaveModified();
  308. //}}AFX_VIRTUAL
  309. // Implementation
  310. public:
  311. virtual ~CFontInfoContainer();
  312. #ifdef _DEBUG
  313. virtual void AssertValid() const;
  314. virtual void Dump(CDumpContext& dc) const;
  315. #endif
  316. // Generated message map functions
  317. protected:
  318. //{{AFX_MSG(CFontInfoContainer)
  319. // NOTE - the ClassWizard will add and remove member functions here.
  320. //}}AFX_MSG
  321. DECLARE_MESSAGE_MAP()
  322. };
  323. #endif