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.

158 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. fefont.c
  5. Abstract:
  6. Text setup display support for FarEast text output.
  7. Author:
  8. Hideyuki Nagase (hideyukn) 01-July-1994
  9. Revision History:
  10. --*/
  11. #include <precomp.h>
  12. #pragma hdrstop
  13. PWCHAR PaddedString(int size, PWCHAR pwch, PWCHAR buffer);
  14. ULONG
  15. FEGetStringColCount(
  16. IN PCWSTR String
  17. )
  18. {
  19. UNICODE_STRING UnicodeString;
  20. //
  21. // Each DBCS char takes 2 columns, and each SBCS char takes 1.
  22. // Thus each char takes as much space as the number of bytes
  23. // in its representation in codepage 932.
  24. //
  25. RtlInitUnicodeString(&UnicodeString,String);
  26. return(RtlxUnicodeStringToOemSize(&UnicodeString)-1);
  27. }
  28. PWSTR
  29. FEPadString(
  30. IN int Size,
  31. IN PCWSTR String
  32. )
  33. {
  34. return(PaddedString(Size,(PWCHAR)String,NULL));
  35. }
  36. /***************************************************************************\
  37. * BOOL IsFullWidth(WCHAR wch)
  38. *
  39. * Determine if the given Unicode char is fullwidth or not.
  40. *
  41. * History:
  42. * 04-08-92 ShunK Created.
  43. \***************************************************************************/
  44. BOOL IsFullWidth(WCHAR wch)
  45. {
  46. if (wch <= 0x007f || (wch >= 0xff60 && wch <= 0xff9f))
  47. return(FALSE); // Half width.
  48. else
  49. return(TRUE); // Full width.
  50. }
  51. /***************************************************************************\
  52. * BOOL SizeOfHalfWidthString(PWCHAR pwch)
  53. *
  54. * Determine size of the given Unicode string, adjusting for half-width chars.
  55. *
  56. * History:
  57. * 08-08-93 FloydR Created.
  58. \***************************************************************************/
  59. int SizeOfHalfWidthString(PWCHAR pwch)
  60. {
  61. int c=0;
  62. while (*pwch) {
  63. if (IsFullWidth(*pwch))
  64. c += 2;
  65. else
  66. c++;
  67. pwch++;
  68. }
  69. return c;
  70. }
  71. /***************************************************************************\
  72. * PWCHAR PaddedString(int size, PWCHAR pwch)
  73. *
  74. * Realize the string, left aligned and padded on the right to the field
  75. * width/precision specified.
  76. *
  77. * Limitations: This uses a static buffer under the assumption that
  78. * no more than one such string is printed in a single 'printf'.
  79. *
  80. * History:
  81. * 11-03-93 FloydR Created.
  82. \***************************************************************************/
  83. WCHAR PaddingBuffer[160];
  84. PWCHAR
  85. PaddedString(int size, PWCHAR pwch, PWCHAR buffer)
  86. {
  87. int realsize;
  88. int fEllipsis = FALSE;
  89. if (buffer==NULL) buffer = PaddingBuffer;
  90. if (size < 0) {
  91. fEllipsis = TRUE;
  92. size = -size;
  93. }
  94. realsize = _snwprintf(buffer, 160, L"%-*.*ws", size, size, pwch);
  95. if (realsize == 0)
  96. return NULL;
  97. if (SizeOfHalfWidthString(buffer) > size) {
  98. do {
  99. buffer[--realsize] = L'\0';
  100. } while (SizeOfHalfWidthString(buffer) > size);
  101. if (fEllipsis && buffer[realsize-1] != L' ') {
  102. WCHAR Trail1 = buffer[realsize-2],
  103. Trail2 = buffer[realsize-1];
  104. int Length;
  105. PWCHAR pwCurrent = &(buffer[realsize-2]);
  106. if(!IsFullWidth(Trail2)) {
  107. *pwCurrent++ = L'.';
  108. } else {
  109. pwCurrent++;
  110. }
  111. if(!IsFullWidth(Trail1)) {
  112. *pwCurrent++ = L'.';
  113. } else {
  114. *pwCurrent++ = L'.';
  115. *pwCurrent++ = L'.';
  116. }
  117. *pwCurrent = L'\0';
  118. Length = SizeOfHalfWidthString(buffer);
  119. while( Length++ < size ) {
  120. *pwCurrent++ = L'.';
  121. *pwCurrent = L'\0';
  122. }
  123. }
  124. }
  125. return buffer;
  126. }