-
-static BOOL FASTCALL
-MetricsCharConvert(WCHAR w, UCHAR *b)
- {
- UNICODE_STRING WString;
- WCHAR WBuf[2];
- ANSI_STRING AString;
- CHAR ABuf[2];
- NTSTATUS Status;
-
- if (L'\0' == w)
- {
- *b = '\0';
- }
- else
- {
- WBuf[0] = w;
- WBuf[1] = L'\0';
- RtlInitUnicodeString(&WString, WBuf);
- ABuf[0] = '*';
- ABuf[1] = L'\0';
- RtlInitAnsiString(&AString, ABuf);
-
- Status = RtlUnicodeStringToAnsiString(&AString, &WString, FALSE);
- if (! NT_SUCCESS(Status))
- {
- SetLastError(RtlNtStatusToDosError(Status));
- return FALSE;
- }
- *b = ABuf[0];
- }
-
- return TRUE;
-}
-
-BOOL FASTCALL
-TextMetricW2A(TEXTMETRICA *tma, TEXTMETRICW *tmw)
-{
- UNICODE_STRING WString;
- WCHAR WBuf[256];
- ANSI_STRING AString;
- CHAR ABuf[256];
- UINT Letter;
- NTSTATUS Status;
-
- tma->tmHeight = tmw->tmHeight;
- tma->tmAscent = tmw->tmAscent;
- tma->tmDescent = tmw->tmDescent;
- tma->tmInternalLeading = tmw->tmInternalLeading;
- tma->tmExternalLeading = tmw->tmExternalLeading;
- tma->tmAveCharWidth = tmw->tmAveCharWidth;
- tma->tmMaxCharWidth = tmw->tmMaxCharWidth;
- tma->tmWeight = tmw->tmWeight;
- tma->tmOverhang = tmw->tmOverhang;
- tma->tmDigitizedAspectX = tmw->tmDigitizedAspectX;
- tma->tmDigitizedAspectY = tmw->tmDigitizedAspectY;
-
- /* The Unicode FirstChar/LastChar need not correspond to the ANSI
- FirstChar/LastChar. For example, if the font contains glyphs for
- letters A-Z and an accented version of the letter e, the Unicode
- FirstChar would be A and the Unicode LastChar would be the accented
- e. If you just translate those to ANSI, the range would become
- letters A-E instead of A-Z.
- We translate all possible ANSI chars to Unicode and find the first
- and last translated character which fall into the Unicode FirstChar/
- LastChar range and return the corresponding ANSI char. */
-
- /* Setup an Ansi string containing all possible letters (note: skip '\0' at
- the beginning since that would be interpreted as end-of-string, handle
- '\0' special later */
- for (Letter = 1; Letter < 256; Letter++)
- {
- ABuf[Letter - 1] = (CHAR) Letter;
- WBuf[Letter - 1] = L' ';
- }
- ABuf[255] = '\0';
- WBuf[255] = L'\0';
- RtlInitAnsiString(&AString, ABuf);
- RtlInitUnicodeString(&WString, WBuf);
-
- /* Find the corresponding Unicode characters */
- Status = RtlAnsiStringToUnicodeString(&WString, &AString, FALSE);
- if (! NT_SUCCESS(Status))
- {
- SetLastError(RtlNtStatusToDosError(Status));
- return FALSE;
- }
-
- /* Scan for the first ANSI character which maps to an Unicode character
- in the range */
- tma->tmFirstChar = '\0';
- if (L'\0' != tmw->tmFirstChar)
- {
- for (Letter = 1; Letter < 256; Letter++)
- {
- if (tmw->tmFirstChar <= WBuf[Letter - 1] &&
- WBuf[Letter - 1] <= tmw->tmLastChar)
- {
- tma->tmFirstChar = (CHAR) Letter;
- break;
- }
- }
- }
-
- /* Scan for the last ANSI character which maps to an Unicode character
- in the range */
- tma->tmLastChar = '\0';
- if (L'\0' != tmw->tmLastChar)
- {
- for (Letter = 255; 0 < Letter; Letter--)
- {
- if (tmw->tmFirstChar <= WBuf[Letter - 1] &&
- WBuf[Letter - 1] <= tmw->tmLastChar)
- {
- tma->tmLastChar = (CHAR) Letter;
- break;
- }
- }
- }
-
- if (! MetricsCharConvert(tmw->tmDefaultChar, &tma->tmDefaultChar) ||
- ! MetricsCharConvert(tmw->tmBreakChar, &tma->tmBreakChar))
- {
- return FALSE;
- }
-
- tma->tmItalic = tmw->tmItalic;
- tma->tmUnderlined = tmw->tmUnderlined;
- tma->tmStruckOut = tmw->tmStruckOut;
- tma->tmPitchAndFamily = tmw->tmPitchAndFamily;
- tma->tmCharSet = tmw->tmCharSet;
-
- return TRUE;
-}
-
-BOOL FASTCALL