Source code of Windows XP (NT5)
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.

262 lines
5.4 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* FontUtil.c -- font table management routines */
  5. #define NOVIRTUALKEYCODES
  6. #define NOCTLMGR
  7. #define NOWINMESSAGES
  8. #define NOWINSTYLES
  9. #define NOCLIPBOARD
  10. #define NOGDICAPMASKS
  11. #define NOSYSMETRICS
  12. #define NOMENUS
  13. #define NOKEYSTATE
  14. #define NORASTEROPS
  15. #define NOSYSCOMMANDS
  16. #define NOSHOWWINDOW
  17. #define NOCOLOR
  18. #define NOATOM
  19. #define NOBITMAP
  20. #define NOICON
  21. #define NOBRUSH
  22. #define NOCREATESTRUCT
  23. #define NOMB
  24. #define NOMSG
  25. #define NOOPENFILE
  26. #define NOPEN
  27. #define NOPOINT
  28. #define NOREGION
  29. #define NOSCROLL
  30. #define NOSOUND
  31. #define NOWH
  32. #define NOWINOFFSETS
  33. #define NOWNDCLASS
  34. #define NOCOMM
  35. #include <windows.h>
  36. #include "mw.h"
  37. #include "cmddefs.h"
  38. #include "docdefs.h"
  39. #include "filedefs.h"
  40. #include "propdefs.h"
  41. #include "fkpdefs.h"
  42. #include "debug.h"
  43. #include "wwdefs.h"
  44. #include "dispdefs.h"
  45. #include "editdefs.h"
  46. #include "str.h"
  47. #include "prmdefs.h"
  48. #include "printdef.h"
  49. #include "fontdefs.h"
  50. extern struct DOD (**hpdocdod)[];
  51. struct FFNTB **HffntbAlloc()
  52. /* returns empty ffntb */
  53. {
  54. struct FFNTB **hffntb;
  55. int cwAlc;
  56. cwAlc = CwFromCch(sizeof(struct FFNTB) - cffnMin * sizeof(struct FFN **));
  57. if (!FNoHeap(hffntb = (struct FFNTB **)HAllocate(cwAlc)))
  58. {
  59. (*hffntb)->iffnMac = 0;
  60. (*hffntb)->fFontMenuValid = FALSE;
  61. }
  62. return(hffntb);
  63. }
  64. FtcAddDocFfn(doc, pffn)
  65. /* adds the described ffn to the ffntb for this doc - returns ftcNil if the
  66. allocation failed */
  67. int doc;
  68. struct FFN *pffn;
  69. {
  70. struct FFNTB **hffntb;
  71. hffntb = HffntbGet(doc);
  72. if (hffntb == 0)
  73. {
  74. hffntb = HffntbAlloc();
  75. if (FNoHeap(hffntb))
  76. return(ftcNil);
  77. (**hpdocdod)[doc].hffntb = hffntb;
  78. }
  79. return(FtcAddFfn(hffntb, pffn));
  80. }
  81. int FtcAddFfn(hffntb, pffn)
  82. /* adds the described ffn to hffntb. returns ftcNil if it fails */
  83. struct FFNTB **hffntb;
  84. struct FFN *pffn;
  85. {
  86. unsigned cb;
  87. int cwAlloc, iffnMac, ftc;
  88. FFID ffid;
  89. struct FFN **hffn;
  90. (*hffntb)->fFontMenuValid = FALSE; /* so fonts on char dropdown get updated */
  91. ftc = ftcNil;
  92. ffid = pffn->ffid;
  93. cb = CchSz( pffn->szFfn );
  94. if (cb > LF_FACESIZE)
  95. {
  96. Assert( FALSE ); /* If we get here, the doc's font tables are prob. bad */
  97. cb = LF_FACESIZE;
  98. }
  99. Assert( cb > 0 );
  100. cwAlloc = CwFromCch( CbFfn( cb ) );
  101. if (!FNoHeap(hffn = (struct FFN **)HAllocate(cwAlloc)))
  102. {
  103. blt(pffn, *hffn, cwAlloc);
  104. (*hffn)->szFfn[ cb - 1 ] = '\0'; /* In case of font name too big */
  105. iffnMac = (*hffntb)->iffnMac + 1;
  106. cwAlloc = CwFromCch(sizeof(struct FFNTB) +
  107. (iffnMac - cffnMin) * sizeof(struct FFN **));
  108. if (FChngSizeH(hffntb, cwAlloc, FALSE))
  109. {
  110. ftc = iffnMac - 1; /* ?! pault */
  111. (*hffntb)->mpftchffn[ftc] = hffn;
  112. (*hffntb)->iffnMac = iffnMac;
  113. }
  114. else
  115. {
  116. FreeH(hffn);
  117. }
  118. }
  119. return(ftc);
  120. }
  121. FEnsurePffn(hffntb, pffn)
  122. /* return TRUE if we were able to add the described font to the table - this
  123. routine is just a convenience, the other pieces aren't that complex to
  124. call. */
  125. struct FFNTB **hffntb;
  126. struct FFN *pffn;
  127. {
  128. if (FtcScanFfn(hffntb, pffn) != ftcNil ||
  129. FtcAddFfn(hffntb, pffn) != ftcNil)
  130. return(TRUE);
  131. return(FALSE);
  132. }
  133. FtcScanDocFfn(doc, pffn)
  134. /* looks for described font in docs ffntb - returns ftcNil if not found */
  135. int doc;
  136. struct FFN *pffn;
  137. {
  138. int ftc;
  139. struct FFNTB **hffntb;
  140. ftc = ftcNil;
  141. hffntb = HffntbGet(doc);
  142. if (hffntb != 0)
  143. ftc = FtcScanFfn(hffntb, pffn);
  144. return(ftc);
  145. }
  146. FtcScanFfn(hffntb, pffn)
  147. struct FFNTB **hffntb;
  148. struct FFN *pffn;
  149. {
  150. int iffn, iffnMac;
  151. struct FFN ***mpftchffn;
  152. mpftchffn = (*hffntb)->mpftchffn;
  153. iffnMac = (*hffntb)->iffnMac;
  154. for (iffn = 0; iffn < iffnMac; iffn++)
  155. {
  156. if (WCompSz(pffn->szFfn, (*mpftchffn[iffn])->szFfn) == 0)
  157. {
  158. /* found it */
  159. if (pffn->ffid != FF_DONTCARE)
  160. {
  161. /* maybe we discovered a family for this font? */
  162. (*mpftchffn[iffn])->ffid = pffn->ffid;
  163. (*mpftchffn[iffn])->chs = pffn->chs;
  164. }
  165. return(iffn);
  166. }
  167. }
  168. return(ftcNil);
  169. }
  170. FtcChkDocFfn(doc, pffn)
  171. /* Adds described font to doc's ffntb if it's not already there - ftcNil is
  172. returned if it wasn't there and couldn't be added */
  173. int doc;
  174. struct FFN *pffn;
  175. {
  176. int ftc;
  177. ftc = FtcScanDocFfn(doc, pffn);
  178. if (ftc == ftcNil)
  179. ftc = FtcAddDocFfn(doc, pffn);
  180. return(ftc);
  181. }
  182. FreeFfntb(hffntb)
  183. struct FFNTB **hffntb;
  184. {
  185. int iffn, iffnMac;
  186. if ((hffntb == 0) || FNoHeap(hffntb))
  187. /* nothing to do */
  188. return;
  189. iffnMac = (*hffntb)->iffnMac;
  190. for (iffn = 0; iffn < iffnMac; iffn++)
  191. FreeH((*hffntb)->mpftchffn[iffn]);
  192. FreeH(hffntb);
  193. }
  194. SmashDocFce(doc)
  195. /* the font table for this doc has scrambled, so we need to disassociate
  196. the corresponding cache entries from the doc */
  197. int doc;
  198. {
  199. extern int vifceMac;
  200. extern union FCID vfcidScreen;
  201. extern union FCID vfcidPrint;
  202. extern struct FCE rgfce[ifceMax];
  203. int ifce;
  204. for (ifce = 0; ifce < vifceMac; ifce++)
  205. if (rgfce[ifce].fcidRequest.strFcid.doc == doc)
  206. rgfce[ifce].fcidRequest.strFcid.ftc = ftcNil;
  207. vfcidScreen.strFcid.ftc = ftcNil;
  208. vfcidPrint.strFcid.ftc = ftcNil;
  209. }
  210.