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.

417 lines
10 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* doprm.c -- MW Property modifying routines */
  5. #define NOCLIPBOARD
  6. #define NOGDICAPMASKS
  7. #define NOCTLMGR
  8. #define NOVIRTUALKEYCODES
  9. #define NOWINMESSAGES
  10. #define NOWINSTYLES
  11. #define NOSYSMETRICS
  12. #define NOMENUS
  13. #define NOICON
  14. #define NOKEYSTATE
  15. #define NORASTEROPS
  16. #define NOSHOWWINDOW
  17. #define NOSYSCOMMANDS
  18. #define NOCREATESTRUCT
  19. #define NOATOM
  20. #define NOMETAFILE
  21. #define NOGDI
  22. #define NOFONT
  23. #define NOBRUSH
  24. #define NOPEN
  25. #define NOBITMAP
  26. #define NOCOLOR
  27. #define NODRAWTEXT
  28. #define NOWNDCLASS
  29. #define NOSOUND
  30. #define NOCOMM
  31. #define NOMB
  32. #define NOMSG
  33. #define NOOPENFILE
  34. #define NORESOURCE
  35. #define NOPOINT
  36. #define NORECT
  37. #define NOREGION
  38. #define NOSCROLL
  39. #define NOTEXTMETRIC
  40. #define NOWH
  41. #define NOWINOFFSETS
  42. #include <windows.h>
  43. #include "mw.h"
  44. #include "cmddefs.h"
  45. #include "filedefs.h"
  46. #include "propdefs.h"
  47. #include "prmdefs.h"
  48. #include "fkpdefs.h"
  49. #include "docdefs.h"
  50. #include "macro.h"
  51. #include "dispdefs.h"
  52. #include "fontdefs.h"
  53. /* E X T E R N A L S */
  54. extern int rgxaRulerSprm[];
  55. extern struct PAP *vppapNormal;
  56. extern struct CHP vchpNormal;
  57. extern CHAR dnsprm[];
  58. extern struct CHP vchpNormal;
  59. extern struct SEP vsepStd;
  60. extern struct SEP vsepNormal;
  61. #ifdef CASHMERE
  62. extern struct TBD rgtbdRulerSprm[];
  63. #endif
  64. /* List of approved font sizes, in half points */
  65. #ifdef INTL
  66. int rghps[csizeApprovedMax] = {8, 12, 16, 20, 24, 28, 36, 48, 60, 72, 96, 144, 254};
  67. #else
  68. int rghps[csizeApprovedMax] = {8, 12, 16, 20, 24, 32, 40, 48, 60, 72, 96, 144, 254};
  69. #endif /* if-else-def INTL */
  70. CHAR *PchFromFc();
  71. /* D O P R M */
  72. DoPrm(struct CHP *pchp, struct PAP *ppap, struct PRM prm)
  73. { /* Apply prm to char and para properties */
  74. if (bPRMNIL(prm))
  75. return;
  76. if (((struct PRM *) &prm)->fComplex)
  77. {
  78. int cch;
  79. CHAR *pfsprm;
  80. struct FPRM *pfprm = (struct FPRM *) PchFromFc(fnScratch,
  81. fcSCRATCHPRM(prm), &cch);
  82. cch = pfprm->cch;
  83. pfsprm = pfprm->grpfsprm;
  84. while (cch > 0)
  85. {
  86. int cchT;
  87. int sprm;
  88. DoSprm(pchp, ppap, sprm = *pfsprm, pfsprm + 1);
  89. if ((cchT = (dnsprm[sprm] & ESPRM_cch)) == 0)
  90. cchT = CchPsprm(pfsprm);
  91. cch -= cchT;
  92. pfsprm += cchT;
  93. }
  94. }
  95. else
  96. /* Simple prm; single sprm */
  97. DoSprm(pchp, ppap, ((struct PRM *) &prm)->sprm,
  98. &((struct PRM *) &prm)->val);
  99. }
  100. /* D O S P R M */
  101. /* Apply a single property modifier to para/char prop */
  102. DoSprm(pchp, ppap, sprm, pval)
  103. struct CHP *pchp;
  104. struct PAP *ppap;
  105. int sprm;
  106. CHAR *pval;
  107. {
  108. int *pvalTo;
  109. int val = *pval;
  110. #ifdef DEBUG
  111. Assert(sprm > 0 && sprm < sprmMax);
  112. #endif
  113. if ((dnsprm[sprm] & ESPRM_sgc) != sgcChar)
  114. {
  115. if (ppap != 0)
  116. {
  117. struct TBD *ptbd;
  118. int rhc;
  119. int fGraphics;
  120. ppap->fStyled = fFalse;
  121. switch (sprm)
  122. {
  123. case sprmPLMarg:
  124. pvalTo = &ppap->dxaLeft;
  125. break;
  126. case sprmPRMarg:
  127. pvalTo = &ppap->dxaRight;
  128. break;
  129. case sprmPFIndent:
  130. pvalTo = &ppap->dxaLeft1;
  131. break;
  132. case sprmPJc:
  133. ppap->jc = val;
  134. return;
  135. #ifdef CASHMERE
  136. case sprmPRuler:
  137. /* Ruler and Ruler1 rely on the fact that rgxaRulerSprm and PAP both
  138. align R, L, L1 in that order.
  139. Ruler: apply the current state of the ruler */
  140. blt(&rgxaRulerSprm[0], &ppap->dxaRight, 3);
  141. blt(&rgtbdRulerSprm[0], ppap->rgtbd, itbdMax * cwTBD);
  142. return;
  143. case sprmPRuler1:
  144. /* as Ruler, except information is at pval+1 and pval+"7" */
  145. bltbyte((CHAR *)(pval + 1), &ppap->dxaRight, 3 * cchINT);
  146. /* append terminating 0 word to tab table */
  147. bltc(bltbyte((CHAR *)(pval + 1 + (3 * cchINT)), ppap->rgtbd,
  148. val - (3 * cchINT)), 0, cchINT);
  149. return;
  150. case sprmPRgtbd:
  151. bltc(bltbyte(pval + 1, ppap->rgtbd,
  152. val), 0, cchINT);
  153. return;
  154. case sprmPKeep:
  155. ppap->fKeep = val;
  156. return;
  157. case sprmPKeepFollow:
  158. ppap->fKeepFollow = val;
  159. return;
  160. #endif
  161. case sprmPDyaLine:
  162. pvalTo = &ppap->dyaLine;
  163. break;
  164. #ifdef CASHMERE
  165. case sprmPDyaBefore:
  166. pvalTo = &ppap->dyaBefore;
  167. break;
  168. case sprmPDyaAfter:
  169. pvalTo = &ppap->dyaAfter;
  170. break;
  171. #endif
  172. case sprmPRhc:
  173. ppap->rhc = val;
  174. return;
  175. case sprmPRhcNorm:
  176. /* (int) dxaLeftAdj + (int) dxaRightAdj */
  177. Assert(*pval == 4);
  178. pval++; /* skip over cch */
  179. ppap->dxaLeft = imax( 0,
  180. ppap->dxaLeft - *(int *) pval);
  181. ppap->dxaRight = imax( 0,
  182. ppap->dxaRight - *((int *) pval + 1));
  183. return;
  184. case sprmPNormal:
  185. rhc = ppap->rhc;
  186. fGraphics = ppap->fGraphics;
  187. blt(vppapNormal, ppap, cwPAPBase);
  188. goto LSame;
  189. case sprmPSame:
  190. rhc = ppap->rhc;
  191. fGraphics = ppap->fGraphics;
  192. /* note: tab terminating 0 MUST be part of value if tab table is to be changed */
  193. bltbyte(pval + 1, ppap, val - 1);
  194. LSame: ppap->rhc = rhc;
  195. ppap->fGraphics = fGraphics;
  196. return;
  197. #ifdef CASHMERE
  198. case sprmPNest:
  199. if (ppap->rgtbd[0].dxa != 0 &&
  200. ppap->rgtbd[0].dxa == ppap->dxaLeft &&
  201. ppap->rgtbd[1].dxa == 0)
  202. ppap->rgtbd[0].dxa += dxaNest;
  203. ppap->dxaLeft += dxaNest;
  204. return;
  205. case sprmPUnNest:
  206. if (ppap->rgtbd[0].dxa != 0 &&
  207. ppap->rgtbd[0].dxa == ppap->dxaLeft &&
  208. ppap->rgtbd[1].dxa == 0)
  209. ppap->rgtbd[0].dxa -= dxaNest;
  210. ppap->dxaLeft = max(0, (int)(ppap->dxaLeft - dxaNest));
  211. return;
  212. case sprmPHang:
  213. ppap->dxaLeft = umin(ppap->dxaLeft + cxaInch, xaRightMax - cxaInch);
  214. ppap->dxaLeft1 = -cxaInch;
  215. ptbd = &ppap->rgtbd[0];
  216. SetWords(ptbd, 0, cwTBD * 2);
  217. ptbd->dxa = ppap->dxaLeft;
  218. /* Inefficient:
  219. ptbd->tlc = tlcWhite;
  220. ptbd->jc = jcLeft;
  221. ++ptbd->dxa = 0 */
  222. return;
  223. #endif
  224. default:
  225. Assert(FALSE);
  226. return;
  227. }
  228. /* common portion for those transferring a single word */
  229. bltbyte(pval, pvalTo, cchINT);
  230. }
  231. return;
  232. }
  233. else
  234. {
  235. if (pchp != 0)
  236. {
  237. int fSpecial;
  238. int ftc, hps;
  239. pchp->fStyled = fFalse;
  240. switch (sprm)
  241. {
  242. /* CHARACTER sprm's */
  243. case sprmCBold:
  244. pchp->fBold = val;
  245. return;
  246. case sprmCItalic:
  247. pchp->fItalic = val;
  248. return;
  249. case sprmCUline:
  250. pchp->fUline = val;
  251. return;
  252. #ifdef CASHMERE
  253. case sprmCOutline:
  254. pchp->fOutline = val;
  255. return;
  256. case sprmCShadow:
  257. pchp->fShadow = val;
  258. return;
  259. case sprmCCsm:
  260. pchp->csm = val;
  261. return;
  262. #endif
  263. case sprmCPos:
  264. /* If going in or out of sub/superscript, alter font size */
  265. if (pchp->hpsPos == 0 && val != 0)
  266. pchp->hps = HpsAlter(pchp->hps, -1);
  267. else if (pchp->hpsPos != 0 && val == 0)
  268. pchp->hps = HpsAlter(pchp->hps, 1);
  269. pchp->hpsPos = val;
  270. return;
  271. case sprmCFtc:
  272. case sprmCChgFtc:
  273. pchp->ftc = val & 0x003f;
  274. pchp->ftcXtra = (val & 0x00c0) >> 6;
  275. return;
  276. case sprmCHps:
  277. pchp->hps = val;
  278. return;
  279. case sprmCChgHps:
  280. pchp->hps = HpsAlter(pchp->hps,
  281. val >= 128 ? val - 256 : val); /* sign extend from char to int */
  282. return;
  283. case sprmCSame:
  284. fSpecial = pchp->fSpecial;
  285. bltbyte(pval, pchp, cchCHP);
  286. pchp->fSpecial = fSpecial;
  287. return;
  288. case sprmCPlain:
  289. fSpecial = pchp->fSpecial;
  290. ftc = FtcFromPchp(pchp);
  291. hps = pchp->hps;
  292. /* If we used to be sub/superscript, increase font size */
  293. if (pchp->hpsPos != 0)
  294. hps = HpsAlter(hps, 1);
  295. blt(&vchpNormal, pchp, cwCHP);
  296. pchp->fSpecial = fSpecial;
  297. pchp->ftc = ftc & 0x003f;
  298. pchp->ftcXtra = (ftc & 0x00c0) >> 6;
  299. pchp->hps = hps;
  300. return;
  301. case sprmCMapFtc:
  302. /* val is ftcMac for mapping */
  303. /* pval+1 points to ftcMac mapping bytes */
  304. ftc = pchp->ftc + (pchp->ftcXtra << 6);
  305. Assert(ftc < val);
  306. ftc = *(pval + 1 + ftc);
  307. pchp->ftc = ftc & 0x003f;
  308. pchp->ftcXtra = (ftc & 0x00c0) >> 6;
  309. return;
  310. case sprmCOldFtc:
  311. ftc = pchp->ftc + (pchp->ftcXtra << 6);
  312. ftc = FtcMapOldFtc(ftc, pval);
  313. pchp->ftc = ftc & 0x003f;
  314. pchp->ftcXtra = (ftc & 0x00c0) >> 6;
  315. return;
  316. default:
  317. Assert(FALSE);
  318. return;
  319. }
  320. }
  321. }
  322. }
  323. /* C C H P S P R M */
  324. /* returns length of sprm's that are of variable or large size.
  325. (cch = (esprm & ESPRM_cch)) == 0 must be checked before calling.*/
  326. CchPsprm(psprm)
  327. CHAR *psprm;
  328. {
  329. return (*psprm == sprmCSame ? cchCHP + 1 :
  330. /* PSame, PRgtbd, PRuler1, CMapFtc, COldFtc: */
  331. *(psprm + 1) + 2);
  332. }
  333. int HpsAlter(hps, ialter)
  334. int hps, ialter;
  335. { /* Return the hps of the approved font size that is ialter steps
  336. away from the given size. I.e.: if ialter is -1, then return
  337. the next smaller size. If alter is 0, return hps. */
  338. /* return 0 if request exceeds limits (11.15.91) v-dougk */
  339. int isize;
  340. if (ialter == 0)
  341. return hps;
  342. /* Find the size just larger than the given size. */
  343. if (ialter > 0)
  344. {
  345. for (isize = 0; isize < csizeApprovedMax - 1; ++isize)
  346. if (rghps[isize] > hps) break;
  347. isize = min(csizeApprovedMax - 1, isize + ialter - 1);
  348. return max(hps, rghps[isize]);
  349. }
  350. else
  351. {
  352. for (isize = 0; isize < csizeApprovedMax; ++isize)
  353. if (rghps[isize] >= hps) break;
  354. isize = max(0, isize + ialter);
  355. return min(hps, rghps[isize]);
  356. }
  357. }
  358. BOOL CanChangeFont(int howmuch)
  359. {
  360. extern struct CHP vchpSel;
  361. extern struct SEL selCur;
  362. int hps;
  363. if (selCur.cpFirst != selCur.cpLim)
  364. return TRUE;
  365. hps = HpsAlter(vchpSel.hps, howmuch);
  366. return ((hps <= rghps[csizeApprovedMax-1]) &&
  367. (hps >= rghps[0]));
  368. }
  369. FtcMapOldFtc(ftc, ftctb)
  370. /* maps an old word font code into one of our selection */
  371. int ftc;
  372. CHAR *ftctb;
  373. {
  374. #ifdef WIN30
  375. int iftc = iftcSwiss; /* Default to SOMEthing! ..pault */
  376. #else
  377. int iftc ;
  378. #endif
  379. if (ftc == 8)
  380. /* helvetica */
  381. iftc = iftcSwiss;
  382. else if (ftc < 16)
  383. iftc = iftcModern;
  384. else if (ftc < 32)
  385. iftc = iftcRoman;
  386. else if (ftc < 40)
  387. iftc = iftcScript;
  388. else if (ftc < 48)
  389. iftc = iftcDecorative;
  390. Assert(iftc < *ftctb);
  391. return(*(ftctb + 1 + iftc));
  392. }
  393.