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.

407 lines
13 KiB

  1. /******************************************************************************
  2. Header File: Glyph Translation.H
  3. These classes define the mapping used from a Unicode or ANSI character to a
  4. character sequence to render said character on a printer. They are content
  5. equivalent to the CTT, RLE and GTT formats used in the various flavors of the
  6. mini-driver architecture.
  7. Copyright (c) 1997 by Microsoft Corporation. All Rights Reserved.
  8. A Pretty Penny Enterprises Production
  9. Change History:
  10. 02-13-97 Bob_Kjelgaard@Prodigy.Net Created it
  11. ******************************************************************************/
  12. #if !defined(GLYPH_TRANSLATION)
  13. #define GLYPH_TRANSLATION
  14. #if defined(LONG_NAMES)
  15. #include "Project Node.H"
  16. #else
  17. #include "ProjNode.H"
  18. #endif
  19. // Win16 CTT formats- since these can't change, I've recoded them to suit.
  20. // Good thing, too- the mapping of direct was bogus- the union implies a word
  21. // aligned structure, but the fact is that direct data is byte-aligned.
  22. class CInvocation : public CObject {
  23. CByteArray m_cbaEncoding;
  24. DWORD m_dwOffset;
  25. DECLARE_SERIAL(CInvocation)
  26. void Encode(BYTE c, CString& cs) const;
  27. public:
  28. CInvocation() {}
  29. void Init(PBYTE pb, unsigned ucb);
  30. unsigned Length() const { return (int)m_cbaEncoding.GetSize(); }
  31. const unsigned Size() const { return 2 * sizeof m_dwOffset; }
  32. void GetInvocation(CString& csReturn) const;
  33. BYTE operator[](unsigned u) const {
  34. return u < Length() ? m_cbaEncoding[u] : 0;
  35. }
  36. CInvocation& operator =(CInvocation& ciRef) {
  37. m_cbaEncoding.Copy(ciRef.m_cbaEncoding);
  38. return *this;
  39. }
  40. void SetInvocation(LPCTSTR lpstrNew);
  41. void NoteOffset(DWORD& dwOffset);
  42. void WriteSelf(CFile& cfTarget) const;
  43. void WriteEncoding(CFile& cfTarget, BOOL bWriteLength = FALSE) const;
  44. virtual void Serialize(CArchive& car);
  45. };
  46. // The following class handles glyph handles and all associated details
  47. class CGlyphHandle : public CObject {
  48. CInvocation m_ciEncoding;
  49. DWORD m_dwCodePage, m_dwidCodePage, m_dwOffset;
  50. WORD m_wIndex;
  51. WORD m_wCodePoint; // Unicode Representation of the glyph
  52. WORD m_wPredefined;
  53. public:
  54. CGlyphHandle() ;
  55. // Atributes
  56. const unsigned RLESize() const { return sizeof m_dwCodePage; }
  57. unsigned CodePage() const { return m_dwidCodePage; } // Only ID matters
  58. WORD CodePoint() const { return m_wCodePoint; }
  59. unsigned CompactSize() const;
  60. unsigned MaximumSize() const {
  61. return CompactSize() ?
  62. sizeof m_wIndex + ((CompactSize() + 1) & ~1) : 0;
  63. }
  64. void GetEncoding(CString& csWhere) {
  65. m_ciEncoding.GetInvocation(csWhere);
  66. }
  67. enum {Modified, Added, Removed};
  68. WORD Predefined() const { return m_wPredefined; }
  69. BOOL operator ==(CGlyphHandle& cghRef);
  70. BOOL PairedRelevant() const { return m_ciEncoding.Length() == 2; }
  71. // Operations
  72. void Init(BYTE b, WORD wIndex, WORD wCode);
  73. void Init(BYTE ab[2], WORD wIndex, WORD wCode);
  74. void Init(PBYTE pb, unsigned ucb, WORD wIndex, WORD wCode);
  75. CGlyphHandle& operator =(CGlyphHandle& cghTemplate);
  76. void RLEOffset(DWORD& dwOffset, const BOOL bCompact);
  77. void GTTOffset(DWORD& dwOffset, BOOL bPaired);
  78. void SetCodePage(DWORD dwidPage, DWORD dwNewPage) {
  79. m_dwCodePage = dwNewPage;
  80. m_dwidCodePage = dwidPage;
  81. }
  82. void NewEncoding(LPCTSTR lpstrNew) {
  83. m_ciEncoding.SetInvocation(lpstrNew);
  84. }
  85. void SetPredefined(WORD wNew) { m_wPredefined = wNew; }
  86. // These write our contents for mini-driver files- they will throw
  87. // exceptions on failure, so use an exception handler to handle errors
  88. void WriteRLE(CFile& cfTarget, WORD wFormat) const;
  89. void WriteGTT(CFile& cfTarget, BOOL bPredefined) const;
  90. enum {GTT, RLEBig, RLESmall}; // Desired encoding format
  91. void WriteEncoding(CFile& cfTarget, WORD wfHow) const;
  92. };
  93. // The next class maintains a record of the runs in the glyph set. It
  94. // generates and merges instances of itself as glyphs are added to the map.
  95. class CRunRecord {
  96. WORD m_wFirst, m_wcGlyphs;
  97. DWORD m_dwOffset; // These are the image...
  98. CRunRecord *m_pcrrNext, *m_pcrrPrevious;
  99. CPtrArray m_cpaGlyphs;
  100. CRunRecord(CGlyphHandle *pcgh, CRunRecord* pcrrPrevious);
  101. CRunRecord(CRunRecord* crrPrevious, WORD wWhere);
  102. CRunRecord(CRunRecord* pcrrPrevious);
  103. CGlyphHandle& Glyph(unsigned u) {
  104. return *(CGlyphHandle *) m_cpaGlyphs[u];
  105. }
  106. const CGlyphHandle& GlyphData(unsigned u) const {
  107. return *(CGlyphHandle *) m_cpaGlyphs[u];
  108. }
  109. public:
  110. CRunRecord();
  111. ~CRunRecord();
  112. unsigned Glyphs() const { return m_wcGlyphs; }
  113. unsigned TotalGlyphs() const;
  114. BOOL MustCompose() const;
  115. unsigned RunCount() const {
  116. return 1 + (m_pcrrNext ? m_pcrrNext -> RunCount() : 0);
  117. }
  118. WORD First() const { return m_wFirst; }
  119. WORD Last() const {
  120. return m_pcrrNext ? m_pcrrNext ->Last() : -1 + m_wFirst + m_wcGlyphs;
  121. }
  122. unsigned ExtraNeeded(BOOL bCompact = TRUE);
  123. const unsigned Size(BOOL bRLE = TRUE) const {
  124. return sizeof m_dwOffset << (unsigned) (!!bRLE);
  125. }
  126. void Collect(CPtrArray& cpaGlyphs) const {
  127. cpaGlyphs.Append(m_cpaGlyphs);
  128. if (m_pcrrNext) m_pcrrNext -> Collect(cpaGlyphs);
  129. }
  130. CGlyphHandle* GetGlyph(unsigned u ) const;
  131. #if defined(_DEBUG) // While the linkage code seems to check out, keep this
  132. // around in case of later problems
  133. BOOL ChainIntact() {
  134. _ASSERTE(m_wcGlyphs == m_cpaGlyphs.GetSize());
  135. for (unsigned u = 0; u < Glyphs(); u++) {
  136. _ASSERTE(Glyph(u).CodePoint() == m_wFirst + u);
  137. }
  138. return !m_pcrrNext || m_pcrrNext -> m_pcrrPrevious == this &&
  139. m_pcrrNext -> ChainIntact();
  140. }
  141. #endif
  142. // Operations
  143. void Add(CGlyphHandle *pcgh);
  144. void Delete(WORD wCodePoint);
  145. void Empty();
  146. void NoteOffset(DWORD& dwOffset, BOOL bRLE, BOOL bPaired);
  147. void NoteExtraOffset(DWORD& dwOffset, const BOOL bCompact);
  148. // File output operations
  149. void WriteSelf(CFile& cfTarget, BOOL bRLE = TRUE) const;
  150. void WriteHandles(CFile& cfTarget, WORD wFormat) const;
  151. void WriteMapTable(CFile& cfTarget, BOOL bPredefined) const;
  152. void WriteEncodings(CFile& cfTarget, WORD wfHow) const;
  153. };
  154. class CCodePageData : public CObject {
  155. DWORD m_dwid;
  156. CInvocation m_ciSelect, m_ciDeselect;
  157. public:
  158. CCodePageData() { m_dwid = 0; }
  159. CCodePageData(DWORD dwid) { m_dwid = dwid; }
  160. // Attributes
  161. DWORD Page() const { return m_dwid; }
  162. void Invocation(CString& csReturn, BOOL bSelect) const;
  163. const unsigned Size() const {
  164. return sizeof m_dwid + 2 * m_ciSelect.Size();
  165. }
  166. BOOL NoInvocation() const {
  167. return !m_ciSelect.Length() && !m_ciDeselect.Length();
  168. }
  169. // Operations
  170. void SetPage(DWORD dwNewPage) { m_dwid = dwNewPage; }
  171. void SetInvocation(LPCTSTR lpstrInvoke, BOOL bSelect);
  172. void SetInvocation(PBYTE pb, unsigned ucb, BOOL bSelect);
  173. void NoteOffsets(DWORD& dwOffset);
  174. void WriteSelf(CFile& cfTarget);
  175. void WriteInvocation(CFile& cfTarget);
  176. };
  177. // This class is the generic class encompassing all glyph translation
  178. // information. We can use it to output any of the other forms.
  179. class CGlyphMap : public CProjectNode {
  180. CSafeMapWordToOb m_csmw2oEncodings; // All of the defined encodings
  181. CRunRecord m_crr;
  182. long m_lidPredefined;
  183. BOOL m_bPaired; // Use paired encoding...
  184. CSafeObArray m_csoaCodePage; // Code page(s) in this map
  185. // Framework support (workspace)
  186. CString m_csSource; // Source CTT File name
  187. // Predefined GTT support- must be in this DLL
  188. static CSafeMapWordToOb m_csmw2oPredefined; // Cache loaded PDTs here
  189. void MergePredefined(); // Use definitions to build "true" GTT
  190. void UnmergePredefined(BOOL bTrackRemovals);
  191. void GenerateRuns();
  192. CCodePageData& CodePage(unsigned u) const {
  193. return *(CCodePageData *) m_csoaCodePage[u];
  194. }
  195. DECLARE_SERIAL(CGlyphMap)
  196. public:
  197. bool ChngedCodePt() { return m_bChngCodePt ; } ;
  198. void SetCodePt( bool b) { m_bChngCodePt = b ; }
  199. // These variables hold parameters for PGetDefaultGlyphset().
  200. WORD m_wFirstChar, m_wLastChar ;
  201. // True iff GTT data should be loaded from resources or built.
  202. bool m_bResBldGTT ;
  203. CTime m_ctSaveTimeStamp ; // The last time this GTT was saved
  204. // Predefined IDs, and a static function for retrieving predefined maps
  205. enum {Wansung = -18, ShiftJIS, GB2312, Big5ToTCA, Big5ToNSA86, JISNoANK,
  206. JIS, KoreanISC, Big5, CodePage863 = -3, CodePage850, CodePage437,
  207. DefaultPage, NoPredefined = 0xFFFF};
  208. static CGlyphMap* Public(WORD wID, WORD wCP = 0, DWORD dwDefCP = 0,
  209. WORD wFirst = 0, WORD wLast = 255) ;
  210. CGlyphMap();
  211. // Attributes
  212. unsigned CodePages() const { return m_csoaCodePage.GetSize(); }
  213. DWORD DefaultCodePage() const { return CodePage(0).Page(); }
  214. unsigned Glyphs() const {
  215. return m_csmw2oEncodings.GetCount();
  216. }
  217. void CodePages(CDWordArray& cdaReturn) const;
  218. unsigned PageID(unsigned u) const { return CodePage(u).Page(); }
  219. long PredefinedID() const { return m_lidPredefined; }
  220. CString PageName(unsigned u) const;
  221. void Invocation(unsigned u, CString& csReturn, BOOL bSelect) const;
  222. void UndefinedPoints(CMapWordToDWord& cmw2dCollector) const;
  223. BOOL OverStrike() const { return m_bPaired; }
  224. const CString& SourceName() { return m_csSource; }
  225. // Operations- Framework support
  226. void SetSourceName(LPCTSTR lpstrNew);
  227. void Load(CByteArray& cbaMap) ; // Load GTT image
  228. //void Load(CByteArray& cbaMap) const; // Load GTT image
  229. // Operations- editor support
  230. void AddPoints(CMapWordToDWord& cmw2dNew); // Add points and pages
  231. void DeleteGlyph(WORD wGlyph);
  232. BOOL RemovePage(unsigned uPage, unsigned uMapTo, bool bDelete = FALSE); // 118880
  233. void SetDefaultCodePage(unsigned u) { CodePage(0).SetPage(u); }
  234. void ChangeCodePage(CPtrArray& cpaGlyphs, DWORD dwidNewPage);
  235. void AddCodePage(DWORD dwidNewPage);
  236. void UsePredefined(long lidPredefined);
  237. void SetInvocation(unsigned u, LPCTSTR lpstrInvoke, BOOL bSelect);
  238. void ChangeEncoding(WORD wCodePoint, LPCTSTR lpstrInvoke);
  239. void OverStrike(BOOL bOn) { m_bPaired = bOn; Changed();}
  240. int ConvertCTT();
  241. BOOL Load(LPCTSTR lpstrName = NULL);
  242. BOOL RLE(CFile& cfTarget);
  243. CGlyphHandle* Glyph(unsigned u);
  244. // Font editor support operations
  245. void Collect(CPtrArray& cpaGlyphs) { // Collect all glyph handles
  246. cpaGlyphs.RemoveAll();
  247. m_crr.Collect(cpaGlyphs);
  248. }
  249. virtual CMDIChildWnd* CreateEditor();
  250. virtual BOOL Generate(CFile& cfGTT);
  251. BOOL SetFileName(LPCTSTR lpstrNew) ;
  252. virtual void Serialize(CArchive& car);
  253. private:
  254. bool m_bChngCodePt;
  255. };
  256. /////////////////////////////////////////////////////////////////////////////
  257. // CGlyphMapContainer document
  258. class CGlyphMapContainer : public CDocument {
  259. CGlyphMap *m_pcgm;
  260. BOOL m_bEmbedded; // From driver, or not?
  261. BOOL m_bSaveSuccessful; // TRUE iff a successful save was performed
  262. protected:
  263. CGlyphMapContainer(); // protected constructor used by dynamic creation
  264. DECLARE_DYNCREATE(CGlyphMapContainer)
  265. // Attributes
  266. public:
  267. CGlyphMap* GlyphMap() { return m_pcgm; }
  268. // Operations
  269. public:
  270. // Constructor- used to create from driver info editor
  271. CGlyphMapContainer(CGlyphMap *pcgm, CString csPath);
  272. // Overrides
  273. // ClassWizard generated virtual function overrides
  274. //{{AFX_VIRTUAL(CGlyphMapContainer)
  275. public:
  276. virtual void Serialize(CArchive& ar); // overridden for document i/o
  277. virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
  278. virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
  279. protected:
  280. virtual BOOL OnNewDocument();
  281. virtual BOOL SaveModified();
  282. //}}AFX_VIRTUAL
  283. // Implementation
  284. public:
  285. virtual ~CGlyphMapContainer();
  286. #ifdef _DEBUG
  287. virtual void AssertValid() const;
  288. virtual void Dump(CDumpContext& dc) const;
  289. #endif
  290. // Generated message map functions
  291. protected:
  292. //{{AFX_MSG(CGlyphMapContainer)
  293. // NOTE - the ClassWizard will add and remove member functions here.
  294. //}}AFX_MSG
  295. DECLARE_MESSAGE_MAP()
  296. };
  297. #endif
  298.