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.

189 lines
4.3 KiB

  1. #include "lstxtmod.h"
  2. #include "lsems.h"
  3. #include "txtils.h"
  4. void GetChanges(LSACT lsact, LSEMS* plsems, long durCur, BOOL fByIsPlus, BYTE* pside, long* pddurChange)
  5. {
  6. *pside = lsact.side;
  7. switch (lsact.kamnt)
  8. {
  9. case kamntNone:
  10. *pddurChange = 0;
  11. break;
  12. case kamntToHalfEm:
  13. *pddurChange = plsems->em2 - durCur;
  14. break;
  15. case kamntToQuarterEm:
  16. *pddurChange = plsems->em4 - durCur;
  17. break;
  18. case kamntToThirdEm:
  19. *pddurChange = plsems->em3 - durCur;
  20. break;
  21. case kamntTo15Sixteenth:
  22. *pddurChange = plsems->em16 - durCur;
  23. break;
  24. case kamntToUserDefinedExpan:
  25. *pddurChange = plsems->udExp - durCur;
  26. break;
  27. case kamntToUserDefinedComp:
  28. *pddurChange = plsems->udComp - durCur;
  29. break;
  30. case kamntByHalfEm:
  31. if (fByIsPlus)
  32. *pddurChange = plsems->em2;
  33. else
  34. *pddurChange = -plsems->em2;
  35. break;
  36. case kamntByQuarterEm:
  37. if (fByIsPlus)
  38. *pddurChange = plsems->em4;
  39. else
  40. *pddurChange = -plsems->em4;
  41. break;
  42. case kamntByEighthEm:
  43. if (fByIsPlus)
  44. *pddurChange = plsems->em8;
  45. else
  46. *pddurChange = -plsems->em8;
  47. break;
  48. case kamntByUserDefinedExpan:
  49. if (fByIsPlus)
  50. *pddurChange = plsems->udExp;
  51. else
  52. *pddurChange = -plsems->udExp;
  53. break;
  54. case kamntByUserDefinedComp:
  55. if (fByIsPlus)
  56. *pddurChange = plsems->udComp;
  57. else
  58. *pddurChange = -plsems->udComp;
  59. break;
  60. default:
  61. Assert(fFalse);
  62. }
  63. if (*pddurChange < -durCur)
  64. *pddurChange = -durCur;
  65. }
  66. void TranslateChanges(BYTE sideRecom, long durAdjustRecom, long durCur, long durRight, long durLeft,
  67. BYTE* psideFinal, long* pdurChange)
  68. {
  69. long durLeftRecom = 0;
  70. long durRightRecom = 0;
  71. Assert(sideRecom != sideNone);
  72. switch (sideRecom)
  73. {
  74. case sideRight:
  75. durLeftRecom = 0;
  76. durRightRecom = durAdjustRecom - durRight;
  77. break;
  78. case sideLeft:
  79. durRightRecom = 0;
  80. durLeftRecom = durAdjustRecom - durLeft;
  81. break;
  82. case sideLeftRight:
  83. durRightRecom = durAdjustRecom >> 1;
  84. durLeftRecom = durAdjustRecom - durRightRecom;
  85. durRightRecom -= durRight;
  86. durLeftRecom -= durLeft;
  87. break;
  88. }
  89. *psideFinal = sideNone;
  90. if (durRightRecom != 0 && durLeftRecom != 0)
  91. *psideFinal = sideLeftRight;
  92. else if (durRightRecom != 0)
  93. *psideFinal = sideRight;
  94. else if (durLeftRecom != 0)
  95. *psideFinal = sideLeft;
  96. *pdurChange = durLeftRecom + durRightRecom;
  97. if (*pdurChange < -durCur)
  98. *pdurChange = -durCur;
  99. }
  100. void ApplyChanges(PILSOBJ pilsobj, long iwch, BYTE side, long ddurChange)
  101. {
  102. long ddurChangeLeft;
  103. long ddurChangeRight;
  104. pilsobj->pdur[iwch] += ddurChange;
  105. InterpretChanges(pilsobj, iwch, side, ddurChange, &ddurChangeLeft, &ddurChangeRight);
  106. Assert(ddurChange == ddurChangeLeft + ddurChangeRight);
  107. pilsobj->pdurLeft[iwch] += ddurChangeLeft;
  108. pilsobj->pdurRight[iwch] += ddurChangeRight;
  109. }
  110. void InterpretChanges(PILSOBJ pilsobj, long iwch, BYTE side, long ddurChange, long* pddurChangeLeft, long* pddurChangeRight)
  111. {
  112. long ddurChangeLeftRight;
  113. switch (side)
  114. {
  115. case sideNone:
  116. Assert(ddurChange == 0);
  117. *pddurChangeLeft = 0;
  118. *pddurChangeRight = 0;
  119. break;
  120. case sideRight:
  121. Assert(pilsobj->pdurRight != NULL);
  122. *pddurChangeLeft = 0;
  123. *pddurChangeRight = ddurChange;
  124. break;
  125. case sideLeft:
  126. Assert(pilsobj->pdurLeft != NULL);
  127. *pddurChangeLeft = ddurChange;
  128. *pddurChangeRight = 0;
  129. break;
  130. case sideLeftRight:
  131. Assert(pilsobj->pdurRight != NULL);
  132. Assert(pilsobj->pdurLeft != NULL);
  133. ddurChangeLeftRight = ddurChange + pilsobj->pdurRight[iwch] + pilsobj->pdurLeft[iwch];
  134. *pddurChangeRight = (ddurChangeLeftRight >> 1) - pilsobj->pdurRight[iwch];
  135. *pddurChangeLeft = (ddurChange - *pddurChangeRight);
  136. break;
  137. }
  138. }
  139. void UndoAppliedChanges(PILSOBJ pilsobj, long iwch, BYTE side, long* pddurChange)
  140. {
  141. Assert(side == sideRight || side == sideLeft);
  142. switch (side)
  143. {
  144. case sideRight:
  145. Assert(pilsobj->pdurRight != NULL);
  146. *pddurChange = -pilsobj->pdurRight[iwch];
  147. pilsobj->pdurRight[iwch] = 0;
  148. break;
  149. case sideLeft:
  150. Assert(pilsobj->pdurLeft != NULL);
  151. *pddurChange = -pilsobj->pdurLeft[iwch];
  152. pilsobj->pdurLeft[iwch] = 0;
  153. break;
  154. }
  155. pilsobj->pdur[iwch] += *pddurChange;
  156. }
  157. void ApplyGlyphChanges(PILSOBJ pilsobj, long igind, long ddurChange)
  158. {
  159. /* while (pilsobj->pdurGind[igind] == 0 && !pislobj->ptxtginf[igind].fFirstInContext)
  160. igind--;
  161. */
  162. pilsobj->pdurGind[igind] += ddurChange;
  163. Assert(pilsobj->pduGright != NULL);
  164. pilsobj->pduGright[igind] += ddurChange;
  165. }