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.

684 lines
19 KiB

  1. #include "lsmem.h"
  2. #include <limits.h>
  3. #include "lsstring.h"
  4. #include "txtils.h"
  5. #include "txtln.h"
  6. #include "txtobj.h"
  7. /* Internal Functions prototypes */
  8. static LSERR CheckReallocCharArrays(PLNOBJ plnobj, long cwch, long iwchLocalStart, long *cwchCorrect);
  9. static LSERR CheckReallocSpacesArrays(PILSOBJ pobj, long cwSpaces);
  10. static LSERR CopyCharsSpacesToDispList(PLNOBJ plnobj, WCHAR* rgwch, long cwch,
  11. long* rgwSpaces, long cwSpaces);
  12. static LSERR CopySpacesToDispList(PLNOBJ plnobj, long iNumOfSpaces, long durSpace);
  13. /* Export Functions implementations */
  14. /*----------------------------------------------------------------------------
  15. %%Function: GetWidth
  16. %%Contact: sergeyge
  17. Fetches widths until end of run or right margin
  18. Uses cache to improve performance
  19. ----------------------------------------------------------------------------*/
  20. LSERR GetWidths(PLNOBJ plnobj, PLSRUN plsrun, long iwchStart, LPWSTR lpwch, LSCP cpFirst, long dcp, long durWidthExceed,
  21. LSTFLOW lstflow, long* pcwchFetched, long* pdurWidth)
  22. {
  23. LSERR lserr;
  24. PILSOBJ pilsobj;
  25. long durWidth;
  26. long cwch;
  27. long iwchDur;
  28. long cwchCorrect;
  29. long cwchIter;
  30. long durWidthIter;
  31. BOOL fNothingReturned = fTrue;
  32. pilsobj = plnobj->pilsobj;
  33. durWidth = 0;
  34. cwch = 0;
  35. iwchDur = iwchStart;
  36. *pcwchFetched = 0;
  37. *pdurWidth = 0;
  38. if (pilsobj->dcpFetchedWidth != 0 && cpFirst == pilsobj->cpFirstFetchedWidth &&
  39. iwchStart == pilsobj->iwchFetchedWidth && lpwch[0] == pilsobj->wchFetchedWidthFirst)
  40. {
  41. Assert(dcp >= pilsobj->dcpFetchedWidth);
  42. cwch = pilsobj->dcpFetchedWidth;
  43. durWidth = pilsobj->durFetchedWidth;
  44. /* FormatRegular assumes that First character exceeding right margin will stop GetCharWidth loop;
  45. Special character could change situation---fix it.
  46. */
  47. if (durWidth > durWidthExceed)
  48. {
  49. while(cwch > 1 && durWidth - durWidthExceed > pilsobj->pdur[iwchStart + cwch - 1])
  50. {
  51. cwch--;
  52. durWidth -= pilsobj->pdur[iwchStart + cwch];
  53. }
  54. }
  55. dcp -= cwch;
  56. durWidthExceed -= durWidth;
  57. iwchDur += cwch;
  58. fNothingReturned = fFalse;
  59. }
  60. while (fNothingReturned || dcp > 0 && durWidthExceed >= 0)
  61. {
  62. lserr = CheckReallocCharArrays(plnobj, dcp, iwchDur, &cwchCorrect);
  63. if (lserr != lserrNone) return lserr;
  64. lserr = (*pilsobj->plscbk->pfnGetRunCharWidths)(pilsobj->pols, plsrun, lsdevReference,
  65. &lpwch[cwch], cwchCorrect, (int)durWidthExceed,
  66. lstflow, (int*)&pilsobj->pdur[iwchDur], &durWidthIter, &cwchIter);
  67. if (lserr != lserrNone) return lserr;
  68. Assert(durWidthIter >= 0);
  69. Assert(durWidthIter <= uLsInfiniteRM);
  70. Assert (durWidthIter <= uLsInfiniteRM - durWidth);
  71. if (durWidthIter > uLsInfiniteRM - durWidth)
  72. return lserrTooLongParagraph;
  73. durWidth += durWidthIter;
  74. durWidthExceed -= durWidthIter;
  75. iwchDur += cwchIter;
  76. cwch += cwchIter;
  77. dcp -= cwchIter;
  78. fNothingReturned = fFalse;
  79. }
  80. *pcwchFetched = cwch;
  81. *pdurWidth = durWidth;
  82. pilsobj->iwchFetchedWidth = iwchStart;
  83. pilsobj->cpFirstFetchedWidth = cpFirst;
  84. pilsobj->dcpFetchedWidth = cwch;
  85. pilsobj->durFetchedWidth = durWidth;
  86. return lserrNone;
  87. }
  88. /* F O R M A T S T R I N G */
  89. /*----------------------------------------------------------------------------
  90. %%Function: FormatString
  91. %%Contact: sergeyge
  92. Formats the local run
  93. ----------------------------------------------------------------------------*/
  94. LSERR FormatString(PLNOBJ plnobj, PTXTOBJ pdobjText, WCHAR* rgwch, long cwch,
  95. long* rgwSpaces, long cwSpaces, long durWidth)
  96. {
  97. LSERR lserr;
  98. PILSOBJ pilsobj;
  99. pilsobj = plnobj->pilsobj;
  100. lserr = CopyCharsSpacesToDispList(plnobj, rgwch, cwch, rgwSpaces, cwSpaces);
  101. if (lserr != lserrNone) return lserr;
  102. /* fill out all related members from strils and output parameters */
  103. pdobjText->iwchLim = pdobjText->iwchLim + cwch;
  104. pdobjText->u.reg.iwSpacesLim = pdobjText->u.reg.iwSpacesLim + cwSpaces;
  105. /* Fix Width Fetching state */
  106. Assert((long)pilsobj->dcpFetchedWidth >= cwch);
  107. Assert(pilsobj->durFetchedWidth >= durWidth);
  108. pilsobj->iwchFetchedWidth = pilsobj->iwchFetchedWidth + cwch;
  109. pilsobj->cpFirstFetchedWidth += cwch;
  110. pilsobj->dcpFetchedWidth -= cwch;
  111. pilsobj->durFetchedWidth -= durWidth;
  112. return lserrNone;
  113. }
  114. /* F I L L R E G U L A R P R E S W I D T H S */
  115. /*----------------------------------------------------------------------------
  116. %%Function: MeasureStringFirst
  117. %%Contact: sergeyge
  118. Calculates dur of one character.
  119. ----------------------------------------------------------------------------*/
  120. LSERR FillRegularPresWidths(PLNOBJ plnobj, PLSRUN plsrun, LSTFLOW lstflow, PTXTOBJ pdobjText)
  121. {
  122. LSERR lserr;
  123. PILSOBJ pilsobj;
  124. int* rgDup;
  125. long dupJunk;
  126. long limDupJunk;
  127. pilsobj = plnobj->pilsobj;
  128. if (pilsobj->fDisplay)
  129. {
  130. rgDup = (int *)&plnobj->pdup[pdobjText->iwchFirst];
  131. if (!pilsobj->fPresEqualRef)
  132. {
  133. lserr = (*pilsobj->plscbk->pfnGetRunCharWidths)(pilsobj->pols, plsrun, lsdevPres,
  134. &pilsobj->pwchOrig[pdobjText->iwchFirst], pdobjText->iwchLim - pdobjText->iwchFirst,
  135. LONG_MAX, lstflow, rgDup, &dupJunk, &limDupJunk);
  136. if (lserr != lserrNone) return lserr;
  137. }
  138. else /* fPresEqualRef */
  139. {
  140. memcpy(rgDup, &pilsobj->pdur[pdobjText->iwchFirst], sizeof(long) * (pdobjText->iwchLim - pdobjText->iwchFirst));
  141. }
  142. }
  143. return lserrNone;
  144. }
  145. /* G E T O N E C H A R D U P */
  146. /*----------------------------------------------------------------------------
  147. %%Function: MeasureStringFirst
  148. %%Contact: sergeyge
  149. Calculates dur of one character.
  150. ----------------------------------------------------------------------------*/
  151. LSERR GetOneCharDur(PILSOBJ pilsobj, PLSRUN plsrun, WCHAR wch, LSTFLOW lstflow, long* pdur)
  152. {
  153. LSERR lserr;
  154. long durSumJunk;
  155. long limDurJunk;
  156. lserr = (*pilsobj->plscbk->pfnGetRunCharWidths)(pilsobj->pols, plsrun, lsdevReference, &wch, 1, LONG_MAX, lstflow,
  157. (int*)pdur, &durSumJunk, &limDurJunk);
  158. if (lserr != lserrNone) return lserr;
  159. return lserrNone;
  160. }
  161. /* G E T O N E C H A R D U P */
  162. /*----------------------------------------------------------------------------
  163. %%Function: GetOneCharDup
  164. %%Contact: sergeyge
  165. Calculates dup of one character
  166. ----------------------------------------------------------------------------*/
  167. LSERR GetOneCharDup(PILSOBJ pilsobj, PLSRUN plsrun, WCHAR wch, LSTFLOW lstflow, long dur, long* pdup)
  168. {
  169. LSERR lserr;
  170. long dupSumJunk;
  171. long limDupJunk;
  172. *pdup = 0;
  173. if (pilsobj->fDisplay)
  174. {
  175. if (!pilsobj->fPresEqualRef)
  176. {
  177. lserr = (*pilsobj->plscbk->pfnGetRunCharWidths)(pilsobj->pols, plsrun, lsdevPres, &wch, 1,
  178. LONG_MAX, lstflow, (int*)pdup, &dupSumJunk, &limDupJunk);
  179. if (lserr != lserrNone) return lserr;
  180. }
  181. else
  182. {
  183. *pdup = dur;
  184. }
  185. }
  186. return lserrNone;
  187. }
  188. /* G E T V I S I D U P */
  189. /*----------------------------------------------------------------------------
  190. %%Function: GetVisiDup
  191. %%Contact: sergeyge
  192. Calculates dup of visi character character
  193. ----------------------------------------------------------------------------*/
  194. LSERR GetVisiCharDup(PILSOBJ pilsobj, PLSRUN plsrun, WCHAR wch, LSTFLOW lstflow, long* pdup)
  195. {
  196. LSERR lserr;
  197. long dupSumJunk;
  198. long limDupJunk;
  199. *pdup = 0;
  200. if (pilsobj->fDisplay)
  201. {
  202. lserr = (*pilsobj->plscbk->pfnGetRunCharWidths)(pilsobj->pols, plsrun, lsdevPres, &wch, 1,
  203. LONG_MAX, lstflow, (int*)pdup, &dupSumJunk, &limDupJunk);
  204. if (lserr != lserrNone) return lserr;
  205. }
  206. return lserrNone;
  207. }
  208. /* A D D C H A R A C T E R W I T H W I D T H */
  209. /*----------------------------------------------------------------------------
  210. %%Function: AddCharacterWithWidth
  211. %%Contact: sergeyge
  212. Writes character code and its width in wchOrig, wch, dup, dur arrays.
  213. Stores character code (in the VISI situation it can be different from wch)
  214. in pilsobj->wchPrev.
  215. ----------------------------------------------------------------------------*/
  216. LSERR AddCharacterWithWidth(PLNOBJ plnobj, PTXTOBJ pdobjText, WCHAR wchOrig, long durWidth, WCHAR wch, long dupWidth)
  217. {
  218. LSERR lserr;
  219. PILSOBJ pilsobj;
  220. long iwchLocalStart;
  221. long cjunk;
  222. pilsobj = plnobj->pilsobj;
  223. iwchLocalStart = pilsobj->wchMac;
  224. lserr = CheckReallocCharArrays(plnobj, 1, iwchLocalStart, &cjunk);
  225. if (lserr != lserrNone) return lserr;
  226. /* Fix cached width information before width in the pdur array is overwritten by durWidth.
  227. Theoretically durWidth can be different from the cached value */
  228. if (pilsobj->dcpFetchedWidth > 0)
  229. {
  230. pilsobj->iwchFetchedWidth ++;
  231. pilsobj->cpFirstFetchedWidth ++;
  232. pilsobj->dcpFetchedWidth --;
  233. pilsobj->durFetchedWidth -= pilsobj->pdur[iwchLocalStart];
  234. }
  235. pilsobj->pwchOrig[iwchLocalStart] = wchOrig;
  236. pilsobj->pdur[iwchLocalStart] = durWidth;
  237. if (pilsobj->fDisplay)
  238. {
  239. plnobj->pwch[iwchLocalStart] = wch;
  240. plnobj->pdup[iwchLocalStart] = dupWidth;
  241. }
  242. pilsobj->wchMac++;
  243. pdobjText->iwchLim++;
  244. Assert(pilsobj->wchMac == pdobjText->iwchLim);
  245. return lserrNone;
  246. }
  247. /* F I X S P A C E S */
  248. /*----------------------------------------------------------------------------
  249. %%Function: FixSpaces
  250. %%Contact: sergeyge
  251. Fixes space character code for the Visi Spaces situation
  252. ----------------------------------------------------------------------------*/
  253. void FixSpaces(PLNOBJ plnobj, PTXTOBJ pdobjText, WCHAR wch)
  254. {
  255. PILSOBJ pilsobj;
  256. long i;
  257. pilsobj = plnobj->pilsobj;
  258. if (pilsobj->fDisplay)
  259. {
  260. for (i = pdobjText->u.reg.iwSpacesFirst; i < pdobjText->u.reg.iwSpacesLim; i++)
  261. {
  262. plnobj->pwch[pilsobj->pwSpaces[i]] = wch;
  263. }
  264. }
  265. }
  266. /* A D D S P A C E S */
  267. /*----------------------------------------------------------------------------
  268. %%Function: AddTrailingSpaces
  269. %%Contact: sergeyge
  270. Adds trailing/bordered spaces to the disp list
  271. ----------------------------------------------------------------------------*/
  272. LSERR AddSpaces(PLNOBJ plnobj, PTXTOBJ pdobjText, long durSpace, long iNumOfSpaces)
  273. {
  274. LSERR lserr;
  275. lserr = CopySpacesToDispList(plnobj, iNumOfSpaces, durSpace);
  276. if (lserr != lserrNone) return lserr;
  277. pdobjText->iwchLim = pdobjText->iwchLim + iNumOfSpaces;
  278. pdobjText->u.reg.iwSpacesLim = pdobjText->u.reg.iwSpacesLim + iNumOfSpaces;
  279. /* Fix Fetched Widths part. For non-bordered case, this procedure is activated for
  280. trailing spaces only, so this state should also be filled with 0s, but
  281. for bordered case it must be flushed
  282. */
  283. FlushStringState(plnobj->pilsobj);
  284. return lserrNone;
  285. }
  286. /* I N C R E A S E W C H M A C B Y @ */
  287. /*----------------------------------------------------------------------------
  288. %%Function: IncreaseWchMacBy2
  289. %%Contact: sergeyge
  290. ----------------------------------------------------------------------------*/
  291. LSERR IncreaseWchMacBy2(PLNOBJ plnobj)
  292. {
  293. LSERR lserr;
  294. long cwch;
  295. lserr = CheckReallocCharArrays(plnobj, 2, plnobj->pilsobj->wchMac, &cwch);
  296. if (lserr != lserrNone) return lserr;
  297. Assert(cwch <= 2 && cwch > 0);
  298. if (cwch == 1)
  299. {
  300. lserr = CheckReallocCharArrays(plnobj, 1, plnobj->pilsobj->wchMac + 1, &cwch);
  301. if (lserr != lserrNone) return lserr;
  302. Assert(cwch == 1);
  303. }
  304. plnobj->pilsobj->wchMac += 2;
  305. return lserrNone;
  306. }
  307. /* Internal Functions Implementation */
  308. /* C H E C K R E A L L O C C H A R A R R A Y S */
  309. /*----------------------------------------------------------------------------
  310. %%Function: ReallocCharArrays
  311. %%Contact: sergeyge
  312. Reallocates character based arrays, increasing them by delta
  313. ----------------------------------------------------------------------------*/
  314. static LSERR CheckReallocCharArrays(PLNOBJ plnobj, long cwch, long iwchLocalStart, long *cwchCorrect)
  315. {
  316. PILSOBJ pilsobj;
  317. WCHAR* pwch;
  318. long* pdup;
  319. long* pdur;
  320. GMAP* pgmap;
  321. TXTINF* ptxtinf;
  322. long delta;
  323. pilsobj = plnobj->pilsobj;
  324. /* pdupPen was made equal to pdup at the CreateLnObj time;
  325. it can be changed to pdupPenAlloc at Adjust time only */
  326. Assert(plnobj->pdup == plnobj->pdupPen);
  327. /* Constant 2 is not random. We need to have 2 extra places for characters
  328. for breaking with AutoHyphen and YSR which adds one charcter and hyphen.
  329. */
  330. if (iwchLocalStart + cwch <= (long)pilsobj->wchMax - 2)
  331. {
  332. *cwchCorrect = cwch;
  333. }
  334. else if (iwchLocalStart < (long)pilsobj->wchMax - 2)
  335. {
  336. *cwchCorrect = pilsobj->wchMax - 2 - iwchLocalStart;
  337. }
  338. else
  339. {
  340. Assert (iwchLocalStart == (long)pilsobj->wchMax - 2);
  341. delta = wchAddM;
  342. pwch = (*pilsobj->plscbk->pfnReallocPtr)(pilsobj->pols, pilsobj->pwchOrig, (pilsobj->wchMax + delta) * sizeof(WCHAR) );
  343. if (pwch == NULL)
  344. {
  345. return lserrOutOfMemory;
  346. }
  347. pilsobj->pwchOrig = pwch;
  348. pwch = (*pilsobj->plscbk->pfnReallocPtr)(pilsobj->pols, plnobj->pwch, (pilsobj->wchMax + delta) * sizeof(WCHAR) );
  349. if (pwch == NULL)
  350. {
  351. return lserrOutOfMemory;
  352. }
  353. plnobj->pwch = pwch;
  354. pdur = (*pilsobj->plscbk->pfnReallocPtr)(pilsobj->pols, pilsobj->pdur, (pilsobj->wchMax + delta) * sizeof(long) );
  355. if (pdur == NULL)
  356. {
  357. return lserrOutOfMemory;
  358. }
  359. pilsobj->pdur = pdur;
  360. pdup = (*pilsobj->plscbk->pfnReallocPtr)(pilsobj->pols, plnobj->pdup, (pilsobj->wchMax + delta) * sizeof(long) );
  361. if (pdup == NULL)
  362. {
  363. return lserrOutOfMemory;
  364. }
  365. plnobj->pdup = pdup;
  366. if (plnobj->pdupPenAlloc != NULL)
  367. {
  368. pdup = (*pilsobj->plscbk->pfnReallocPtr)(pilsobj->pols, plnobj->pdupPenAlloc, (pilsobj->wchMax + delta) * sizeof(long) );
  369. if (pdup == NULL)
  370. {
  371. return lserrOutOfMemory;
  372. }
  373. plnobj->pdupPenAlloc = pdup;
  374. }
  375. if (plnobj->pgmap != NULL)
  376. {
  377. pgmap = (*pilsobj->plscbk->pfnReallocPtr)(pilsobj->pols, plnobj->pgmap, (pilsobj->wchMax + delta) * sizeof(GMAP) );
  378. if (pgmap == NULL)
  379. {
  380. return lserrOutOfMemory;
  381. }
  382. plnobj->pgmap = pgmap;
  383. }
  384. if (pilsobj->pdurLeft != NULL)
  385. {
  386. pdur = (*pilsobj->plscbk->pfnReallocPtr)(pilsobj->pols, pilsobj->pdurLeft, (pilsobj->wchMax + delta) * sizeof(long) );
  387. if (pdur == NULL)
  388. {
  389. return lserrOutOfMemory;
  390. }
  391. pilsobj->pdurLeft = pdur;
  392. memset(&pilsobj->pdurLeft[pilsobj->wchMax], 0, sizeof(long) * delta );
  393. }
  394. if (pilsobj->pdurRight != NULL)
  395. {
  396. pdur = (*pilsobj->plscbk->pfnReallocPtr)(pilsobj->pols, pilsobj->pdurRight, (pilsobj->wchMax + delta) * sizeof(long) );
  397. if (pdur == NULL)
  398. {
  399. return lserrOutOfMemory;
  400. }
  401. pilsobj->pdurRight = pdur;
  402. memset(&pilsobj->pdurRight[pilsobj->wchMax], 0, sizeof(long) * delta);
  403. }
  404. if (pilsobj->pduAdjust != NULL)
  405. {
  406. pdur = (*pilsobj->plscbk->pfnReallocPtr)(pilsobj->pols, pilsobj->pduAdjust, (pilsobj->wchMax + delta) * sizeof(long) );
  407. if (pdur == NULL)
  408. {
  409. return lserrOutOfMemory;
  410. }
  411. pilsobj->pduAdjust = pdur;
  412. }
  413. if (pilsobj->ptxtinf != NULL)
  414. {
  415. ptxtinf = (*pilsobj->plscbk->pfnReallocPtr)(pilsobj->pols, pilsobj->ptxtinf, (pilsobj->wchMax + delta) * sizeof(TXTINF) );
  416. if (ptxtinf == NULL)
  417. {
  418. return lserrOutOfMemory;
  419. }
  420. pilsobj->ptxtinf = ptxtinf;
  421. memset(&pilsobj->ptxtinf[pilsobj->wchMax], 0, sizeof(TXTINF) * delta);
  422. }
  423. pilsobj->wchMax += delta;
  424. plnobj->wchMax = pilsobj->wchMax;
  425. *cwchCorrect = delta;
  426. if (cwch < delta)
  427. *cwchCorrect = cwch;
  428. }
  429. /* see comment and Assert at the beginning of the file */
  430. plnobj->pdupPen = plnobj->pdup;
  431. return lserrNone;
  432. }
  433. /* C H E C K R E A L L O C S P A C E S A R R A Y S */
  434. /*----------------------------------------------------------------------------
  435. %%Function: CheckReallocSpacesArrays
  436. %%Contact: sergeyge
  437. Checks that there is enough space wSpaces
  438. to accomodate characters & spaces from the current local run.
  439. Reallocates these arrays if it is needed.
  440. ----------------------------------------------------------------------------*/
  441. static LSERR CheckReallocSpacesArrays(PILSOBJ pilsobj, long cwSpaces)
  442. {
  443. long iwSpacesLocalStart;
  444. long delta;
  445. long* pwSpaces;
  446. iwSpacesLocalStart = pilsobj->wSpacesMac;
  447. /* check that there is enough space for spaces in pwSpaces */
  448. if (iwSpacesLocalStart + cwSpaces > pilsobj->wSpacesMax)
  449. {
  450. delta = wchAddM;
  451. if (delta < iwSpacesLocalStart + cwSpaces - pilsobj->wSpacesMax)
  452. {
  453. delta = iwSpacesLocalStart + cwSpaces - pilsobj->wSpacesMax;
  454. }
  455. pwSpaces = (*pilsobj->plscbk->pfnReallocPtr)(pilsobj->pols, pilsobj->pwSpaces, (pilsobj->wSpacesMax + delta) * sizeof(long) );
  456. if (pwSpaces == NULL)
  457. {
  458. return lserrOutOfMemory;
  459. }
  460. pilsobj->pwSpaces = pwSpaces;
  461. pilsobj->wSpacesMax += delta;
  462. }
  463. return lserrNone;
  464. }
  465. /* C O P Y C H A R S S P A C E S T O D I S P L I S T */
  466. /*----------------------------------------------------------------------------
  467. %%Function: CopyCharsSpacesToDispList
  468. %%Contact: sergeyge
  469. Fills wch, dur and wSpaces arrays
  470. ----------------------------------------------------------------------------*/
  471. static LSERR CopyCharsSpacesToDispList(PLNOBJ plnobj, WCHAR* rgwch, long cwch,
  472. long* rgwSpaces, long cwSpaces)
  473. {
  474. LSERR lserr;
  475. PILSOBJ pilsobj;
  476. long iwchLocalStart;
  477. long iwSpacesLocalStart;
  478. long i;
  479. pilsobj = plnobj->pilsobj;
  480. iwchLocalStart = pilsobj->wchMac;
  481. iwSpacesLocalStart = pilsobj->wSpacesMac;
  482. /* check that there is enough space for characters and their widths in pwch and pdup arrays */
  483. lserr = CheckReallocSpacesArrays(pilsobj, cwSpaces);
  484. if (lserr != lserrNone) return lserr;
  485. /* fill pwch array */
  486. memcpy(&pilsobj->pwchOrig[iwchLocalStart], rgwch, sizeof(rgwch[0]) * cwch);
  487. memcpy(&plnobj->pwch[iwchLocalStart], rgwch, sizeof(rgwch[0]) * cwch);
  488. pilsobj->wchMac += cwch;
  489. /* fill pwSpaces array, note that spaces with idexes greater than cwch should not be copied */
  490. for (i=0; i < cwSpaces && rgwSpaces[i] < cwch; i++)
  491. {
  492. pilsobj->pwSpaces[iwSpacesLocalStart + i] = iwchLocalStart + rgwSpaces[i];
  493. }
  494. pilsobj->wSpacesMac += i;
  495. return lserrNone;
  496. }
  497. /* C O P Y S P A C E S T O D I S P L I S T */
  498. /*----------------------------------------------------------------------------
  499. %%Function: CopyTrailingSpacesToDispList
  500. %%Contact: sergeyge
  501. Fills wch, dur, dup, wSpaces arrays with the trailing spaces info
  502. ----------------------------------------------------------------------------*/
  503. static LSERR CopySpacesToDispList(PLNOBJ plnobj, long iNumOfSpaces, long durSpace)
  504. {
  505. LSERR lserr;
  506. PILSOBJ pilsobj;
  507. long iwchLocalStart;
  508. long iwSpacesLocalStart;
  509. long i;
  510. long cwch;
  511. long iwchStartCheck;
  512. long cwchCorrect;
  513. pilsobj = plnobj->pilsobj;
  514. iwchLocalStart = pilsobj->wchMac;
  515. iwSpacesLocalStart = pilsobj->wSpacesMac;
  516. cwch = iNumOfSpaces;
  517. iwchStartCheck = iwchLocalStart;
  518. while (cwch > 0)
  519. {
  520. lserr = CheckReallocCharArrays(plnobj, cwch, iwchStartCheck, &cwchCorrect);
  521. if (lserr != lserrNone) return lserr;
  522. iwchStartCheck += cwchCorrect;
  523. cwch -= cwchCorrect;
  524. }
  525. lserr = CheckReallocSpacesArrays(pilsobj, iNumOfSpaces);
  526. if (lserr != lserrNone) return lserr;
  527. for (i=0; i < iNumOfSpaces; i++)
  528. {
  529. plnobj->pwch[iwchLocalStart + i] = pilsobj->wchSpace;
  530. pilsobj->pwchOrig[iwchLocalStart + i] = pilsobj->wchSpace;
  531. pilsobj->pdur[iwchLocalStart + i] = durSpace;
  532. pilsobj->pwSpaces[iwSpacesLocalStart + i] = iwchLocalStart + i;
  533. }
  534. pilsobj->wchMac += iNumOfSpaces;
  535. pilsobj->wSpacesMac += iNumOfSpaces;
  536. return lserrNone;
  537. }
  538. /* F L A S H S T R I N G S T A T E */
  539. /*----------------------------------------------------------------------------
  540. %%Function: FlashStringState
  541. %%Contact: sergeyge
  542. ----------------------------------------------------------------------------*/
  543. void FlushStringState(PILSOBJ pilsobj)
  544. {
  545. pilsobj->iwchFetchedWidth = 0;
  546. pilsobj->cpFirstFetchedWidth = 0;
  547. pilsobj->dcpFetchedWidth = 0;
  548. pilsobj->durFetchedWidth = 0;
  549. }