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.

312 lines
6.2 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* format2.c -- MW formatting routines */
  5. /* Less used subroutines */
  6. #define NOGDICAPMASKS
  7. #define NOCTLMGR
  8. #define NOVIRTUALKEYCODES
  9. #define NOWINMESSAGES
  10. #define NOWINSTYLES
  11. #define NOMENUS
  12. #define NOKEYSTATE
  13. #define NOGDI
  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 NOFONT
  25. #define NOMSG
  26. #define NOOPENFILE
  27. #define NOPEN
  28. #define NOPOINT
  29. #define NOREGION
  30. #define NOSCROLL
  31. #define NOSOUND
  32. #define NOWH
  33. #define NOWINOFFSETS
  34. #define NOWNDCLASS
  35. #define NOCOMM
  36. #include <windows.h>
  37. #include "mw.h"
  38. #include "editdefs.h"
  39. #include "cmddefs.h"
  40. #include "fmtdefs.h"
  41. #include "propdefs.h"
  42. #define NOKCCODES
  43. #include "ch.h"
  44. #include "docdefs.h"
  45. #include "ffdefs.h"
  46. #include "filedefs.h"
  47. #include "fkpdefs.h"
  48. #include "printdef.h"
  49. #include "str.h"
  50. #include "wwdefs.h"
  51. extern struct FLI vfli;
  52. extern struct SEP vsepAbs;
  53. extern typeCP vcpFirstSectCache;
  54. extern typeCP vcpFetch;
  55. extern int vcchFetch;
  56. extern CHAR *vpchFetch;
  57. extern int vpgn;
  58. extern CHAR stBuf[];
  59. extern struct DOD (**hpdocdod)[];
  60. extern struct WWD rgwwd[];
  61. extern typeCP cpMinDocument;
  62. int CchExpPgn(pch, pgn, nfc, flm, cchMax)
  63. CHAR *pch;
  64. unsigned pgn, cchMax;
  65. int nfc, flm;
  66. {
  67. #ifdef CASHMERE
  68. static CHAR rgchUCRoman[] = "IVIIIXLXXXCDCCCMMM???";
  69. static CHAR rgchLCRoman[] = "iviiixlxxxcdcccmmm???";
  70. #define cchRgchDigit 5
  71. #endif /* CASMERE */
  72. if (flm & flmPrinting)
  73. {
  74. #ifdef CASHMERE
  75. switch (nfc)
  76. {
  77. int cch, ich, chLetter;
  78. case nfcArabic:
  79. if (cchMax < cchMaxNum)
  80. return 0;
  81. return ncvtu(pgn, &pch);
  82. case nfcUCRoman:
  83. return CchStuffRoman(&pch, pgn, rgchUCRoman, cchMax);
  84. case nfcLCRoman:
  85. return CchStuffRoman(&pch, pgn, rgchLCRoman, cchMax);
  86. case nfcUCLetter:
  87. case nfcLCLetter:
  88. if ((cch = (pgn - 1) / 26 + 1) > cchMax)
  89. return 0;
  90. chLetter = (pgn - 1) % 26 + (nfc == nfcUCLetter ? 'A' : 'a');
  91. for (ich = 0; ich < cch; ich++)
  92. pch[ich] = chLetter;
  93. return cch;
  94. }
  95. #else /* not CASHMERE */
  96. if (cchMax < cchMaxNum)
  97. return 0;
  98. return ncvtu(pgn, &pch);
  99. }
  100. #endif /* not CASHMERE */
  101. else
  102. {
  103. int cch;
  104. cch = CchChStuff(&pch, chLParen, cchMax);
  105. cch += CchStuffIdstr(&pch, IDSTRChPage, cchMax - cch);
  106. cch += CchChStuff(&pch, chRParen, cchMax - cch);
  107. return cch;
  108. }
  109. }
  110. /* C C H S T U F F I D S T R */
  111. int CchStuffIdstr(ppch, idstr, cchMax)
  112. CHAR **ppch;
  113. IDSTR idstr;
  114. int cchMax;
  115. {
  116. int cch;
  117. CHAR st[cchMaxExpand]; /* note: we assume no individual idstr
  118. will have a length > cchMaxExpand */
  119. FillStId(st, idstr, sizeof(st));
  120. cch = max(0, min(cchMax, st[0]));
  121. bltbyte(&st[1], *ppch, cch);
  122. (*ppch) += cch;
  123. return cch;
  124. }
  125. /* C C H C H S T U F F */
  126. int CchChStuff(ppch, ch, cchMax)
  127. CHAR **ppch;
  128. CHAR ch;
  129. int cchMax;
  130. {
  131. if(cchMax > 0)
  132. {
  133. **ppch = ch;
  134. (*ppch)++;
  135. return 1;
  136. }
  137. else
  138. return 0;
  139. }
  140. #ifdef CASHMERE
  141. int CchStuffRoman(ppch, u, rgch, cchMax)
  142. CHAR **ppch, *rgch;
  143. unsigned u, cchMax;
  144. {
  145. static CHAR mpdgcch[10] =
  146. { 0, 1, 2, 3, 2, 1, 2, 3, 4, 2 };
  147. static CHAR mpdgich[10] =
  148. { 0, 0, 2, 2, 0, 1, 1, 1, 1, 4 };
  149. int cch, cchDone;
  150. cchDone = 0;
  151. if (u >= 10)
  152. {
  153. cchDone = CchStuffRoman(ppch, u / 10, rgch + cchRgchDigit, cchMax);
  154. cchMax -= cchDone;
  155. u %= 10;
  156. }
  157. cch = mpdgcch[u];
  158. if (cch > cchMax || cch == 0)
  159. return cchDone;
  160. bltbyte(&rgch[mpdgich[u]], *ppch, cch);
  161. *ppch += cch;
  162. return cch + cchDone;
  163. }
  164. #endif /* CASHMERE */
  165. int FFormatSpecials(pifi, flm, nfc)
  166. struct IFI *pifi;
  167. int flm;
  168. int nfc;
  169. { /* A run of special characters was encountered; format it */
  170. /* Return true unless wordwrap required */
  171. int cch;
  172. int cchPr;
  173. int ich;
  174. int dxp;
  175. int dxpPr;
  176. int sch;
  177. CHAR *pchPr;
  178. while (pifi->ichFetch < vcchFetch && pifi->xpPr <= pifi->xpPrRight)
  179. {
  180. #ifdef CASHMERE
  181. switch (sch = vpchFetch[pifi->ichFetch++])
  182. {
  183. case schPage:
  184. cch = CchExpPgn(&vfli.rgch[pifi->ich], vpgn, nfc, flm,
  185. ichMaxLine - pifi->ich);
  186. break;
  187. case schFootnote:
  188. cch = CchExpFtn(&vfli.rgch[pifi->ich], vcpFetch +
  189. pifi->ichFetch - 1, flm, ichMaxLine - pifi->ich);
  190. break;
  191. default:
  192. cch = CchExpUnknown(&vfli.rgch[pifi->ich], flm, ichMaxLine -
  193. pifi->ich);
  194. break;
  195. }
  196. #else /* not CASHMERE */
  197. pchPr = &vfli.rgch[pifi->ich];
  198. if ((sch = vpchFetch[pifi->ichFetch]) == schPage &&
  199. (wwdCurrentDoc.fEditHeader || wwdCurrentDoc.fEditFooter || ((flm &
  200. flmPrinting) && vcpFetch + (typeCP)pifi->ichFetch < cpMinDocument)))
  201. {
  202. cch = CchExpPgn(pchPr, vpgn, nfc, flm, ichMaxLine - pifi->ich);
  203. if (flm & flmPrinting)
  204. {
  205. cchPr = cch;
  206. }
  207. else
  208. {
  209. /* Assume that vsepAbs has been set up by FormatLine(). */
  210. cchPr = CchExpPgn(pchPr = &stBuf[0], vsepAbs.pgnStart == pgnNil
  211. ? 1 : vsepAbs.pgnStart, nfc, flmPrinting, ichMaxLine -
  212. pifi->ich);
  213. }
  214. }
  215. else
  216. {
  217. cch = cchPr = CchExpUnknown(pchPr, flm, ichMaxLine - pifi->ich);
  218. }
  219. pifi->ichFetch++;
  220. #endif /* not CASHMERE */
  221. dxpPr = 0;
  222. for (ich = 0; ich < cchPr; ++ich, ++pchPr)
  223. {
  224. dxpPr += DxpFromCh(*pchPr, true);
  225. }
  226. pifi->xpPr += dxpPr;
  227. if (flm & flmPrinting)
  228. {
  229. dxp = dxpPr;
  230. }
  231. else
  232. {
  233. dxp = 0;
  234. for (ich = pifi->ich; ich < pifi->ich + cch; ++ich)
  235. {
  236. dxp += DxpFromCh(vfli.rgch[ich], false);
  237. }
  238. }
  239. vfli.rgch[pifi->ich] = sch;
  240. pifi->xp += (vfli.rgdxp[pifi->ich++] = dxp);
  241. if (pifi->xpPr > pifi->xpPrRight)
  242. {
  243. return (vcpFetch == vfli.cpMin);
  244. }
  245. }
  246. pifi->fPrevSpace = false;
  247. return true;
  248. }
  249. int CchExpUnknown(pch, flm, cchMax)
  250. CHAR *pch;
  251. int flm, cchMax;
  252. {
  253. int cch;
  254. #ifdef CASHMERE
  255. cch = CchChStuff(&pch, chLParen, cchMax);
  256. cch += CchChStuff(&pch, chQMark, cchMax - cch);
  257. cch += CchChStuff(&pch, chRParen, cchMax - cch);
  258. #else /* not CASHMERE */
  259. cch = CchChStuff(&pch, chStar, cchMax);
  260. #endif /* not CASHMERE */
  261. return cch;
  262. }
  263. #ifdef CASHMERE
  264. int CchExpFtn(pch, cp, flm, cchMax)
  265. CHAR *pch;
  266. typeCP cp;
  267. int flm, cchMax;
  268. {
  269. int doc = vfli.doc;
  270. if (cchMax < cchMaxNum)
  271. return 0;
  272. if (cp >= CpMacText(doc))
  273. cp = CpRefFromFtn(doc, cp);
  274. CacheSect(doc, cp);
  275. return ncvtu(IfndFromCp(doc, cp) - IfndFromCp(doc, vcpFirstSectCache) + 1,
  276. &pch);
  277. }
  278. #endif /* CASHMERE */
  279.