3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/gdi32/object/font.c
17 * For TranslateCharsetInfo
19 #define MAXTCIINDEX 32
20 static const CHARSETINFO FONT_tci
[MAXTCIINDEX
] = {
22 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
23 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
24 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
25 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
26 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
27 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
28 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
29 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
30 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
31 /* reserved by ANSI */
32 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
33 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
34 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
35 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
36 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
37 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
38 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
40 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
41 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
42 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
43 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
44 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
45 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
46 /* reserved for alternate ANSI and OEM */
47 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
48 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
49 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
50 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
51 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
52 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
53 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
54 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
55 /* reserved for system */
56 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
57 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
60 #define INITIAL_FAMILY_COUNT 64
62 /***********************************************************************
63 * TEXTMETRIC conversion functions.
65 static void FONT_TextMetricWToA(const TEXTMETRICW
*ptmW
, LPTEXTMETRICA ptmA
)
67 ptmA
->tmHeight
= ptmW
->tmHeight
;
68 ptmA
->tmAscent
= ptmW
->tmAscent
;
69 ptmA
->tmDescent
= ptmW
->tmDescent
;
70 ptmA
->tmInternalLeading
= ptmW
->tmInternalLeading
;
71 ptmA
->tmExternalLeading
= ptmW
->tmExternalLeading
;
72 ptmA
->tmAveCharWidth
= ptmW
->tmAveCharWidth
;
73 ptmA
->tmMaxCharWidth
= ptmW
->tmMaxCharWidth
;
74 ptmA
->tmWeight
= ptmW
->tmWeight
;
75 ptmA
->tmOverhang
= ptmW
->tmOverhang
;
76 ptmA
->tmDigitizedAspectX
= ptmW
->tmDigitizedAspectX
;
77 ptmA
->tmDigitizedAspectY
= ptmW
->tmDigitizedAspectY
;
78 ptmA
->tmFirstChar
= ptmW
->tmFirstChar
> 255 ? 255 : ptmW
->tmFirstChar
;
79 ptmA
->tmLastChar
= ptmW
->tmLastChar
> 255 ? 255 : ptmW
->tmLastChar
;
80 ptmA
->tmDefaultChar
= ptmW
->tmDefaultChar
> 255 ? 255 : ptmW
->tmDefaultChar
;
81 ptmA
->tmBreakChar
= ptmW
->tmBreakChar
> 255 ? 255 : ptmW
->tmBreakChar
;
82 ptmA
->tmItalic
= ptmW
->tmItalic
;
83 ptmA
->tmUnderlined
= ptmW
->tmUnderlined
;
84 ptmA
->tmStruckOut
= ptmW
->tmStruckOut
;
85 ptmA
->tmPitchAndFamily
= ptmW
->tmPitchAndFamily
;
86 ptmA
->tmCharSet
= ptmW
->tmCharSet
;
89 /***********************************************************************
92 * Returns a Unicode translation of str using the charset of the
93 * currently selected font in hdc. If count is -1 then str is assumed
94 * to be '\0' terminated, otherwise it contains the number of bytes to
95 * convert. If plenW is non-NULL, on return it will point to the
96 * number of WCHARs that have been written. If pCP is non-NULL, on
97 * return it will point to the codepage used in the conversion. The
98 * caller should free the returned LPWSTR from the process heap
101 static LPWSTR
FONT_mbtowc(HDC hdc
, LPCSTR str
, INT count
, INT
*plenW
, UINT
*pCP
)
103 UINT cp
= GdiGetCodePage( hdc
);
107 if(count
== -1) count
= strlen(str
);
108 lenW
= MultiByteToWideChar(cp
, 0, str
, count
, NULL
, 0);
109 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
*sizeof(WCHAR
));
110 MultiByteToWideChar(cp
, 0, str
, count
, strW
, lenW
);
111 DPRINT("mapped %s -> %S\n", str
, strW
);
112 if(plenW
) *plenW
= lenW
;
119 MetricsCharConvert(WCHAR w
, UCHAR
*b
)
121 UNICODE_STRING WString
;
135 RtlInitUnicodeString(&WString
, WBuf
);
138 RtlInitAnsiString(&AString
, ABuf
);
140 Status
= RtlUnicodeStringToAnsiString(&AString
, &WString
, FALSE
);
141 if (! NT_SUCCESS(Status
))
143 SetLastError(RtlNtStatusToDosError(Status
));
153 TextMetricW2A(TEXTMETRICA
*tma
, TEXTMETRICW
*tmw
)
155 UNICODE_STRING WString
;
162 tma
->tmHeight
= tmw
->tmHeight
;
163 tma
->tmAscent
= tmw
->tmAscent
;
164 tma
->tmDescent
= tmw
->tmDescent
;
165 tma
->tmInternalLeading
= tmw
->tmInternalLeading
;
166 tma
->tmExternalLeading
= tmw
->tmExternalLeading
;
167 tma
->tmAveCharWidth
= tmw
->tmAveCharWidth
;
168 tma
->tmMaxCharWidth
= tmw
->tmMaxCharWidth
;
169 tma
->tmWeight
= tmw
->tmWeight
;
170 tma
->tmOverhang
= tmw
->tmOverhang
;
171 tma
->tmDigitizedAspectX
= tmw
->tmDigitizedAspectX
;
172 tma
->tmDigitizedAspectY
= tmw
->tmDigitizedAspectY
;
174 /* The Unicode FirstChar/LastChar need not correspond to the ANSI
175 FirstChar/LastChar. For example, if the font contains glyphs for
176 letters A-Z and an accented version of the letter e, the Unicode
177 FirstChar would be A and the Unicode LastChar would be the accented
178 e. If you just translate those to ANSI, the range would become
179 letters A-E instead of A-Z.
180 We translate all possible ANSI chars to Unicode and find the first
181 and last translated character which fall into the Unicode FirstChar/
182 LastChar range and return the corresponding ANSI char. */
184 /* Setup an Ansi string containing all possible letters (note: skip '\0' at
185 the beginning since that would be interpreted as end-of-string, handle
186 '\0' special later */
187 for (Letter
= 1; Letter
< 256; Letter
++)
189 ABuf
[Letter
- 1] = (CHAR
) Letter
;
190 WBuf
[Letter
- 1] = L
' ';
194 RtlInitAnsiString(&AString
, ABuf
);
195 RtlInitUnicodeString(&WString
, WBuf
);
197 /* Find the corresponding Unicode characters */
198 Status
= RtlAnsiStringToUnicodeString(&WString
, &AString
, FALSE
);
199 if (! NT_SUCCESS(Status
))
201 SetLastError(RtlNtStatusToDosError(Status
));
205 /* Scan for the first ANSI character which maps to an Unicode character
207 tma
->tmFirstChar
= '\0';
208 if (L
'\0' != tmw
->tmFirstChar
)
210 for (Letter
= 1; Letter
< 256; Letter
++)
212 if (tmw
->tmFirstChar
<= WBuf
[Letter
- 1] &&
213 WBuf
[Letter
- 1] <= tmw
->tmLastChar
)
215 tma
->tmFirstChar
= (CHAR
) Letter
;
221 /* Scan for the last ANSI character which maps to an Unicode character
223 tma
->tmLastChar
= '\0';
224 if (L
'\0' != tmw
->tmLastChar
)
226 for (Letter
= 255; 0 < Letter
; Letter
--)
228 if (tmw
->tmFirstChar
<= WBuf
[Letter
- 1] &&
229 WBuf
[Letter
- 1] <= tmw
->tmLastChar
)
231 tma
->tmLastChar
= (CHAR
) Letter
;
237 if (! MetricsCharConvert(tmw
->tmDefaultChar
, &tma
->tmDefaultChar
) ||
238 ! MetricsCharConvert(tmw
->tmBreakChar
, &tma
->tmBreakChar
))
243 tma
->tmItalic
= tmw
->tmItalic
;
244 tma
->tmUnderlined
= tmw
->tmUnderlined
;
245 tma
->tmStruckOut
= tmw
->tmStruckOut
;
246 tma
->tmPitchAndFamily
= tmw
->tmPitchAndFamily
;
247 tma
->tmCharSet
= tmw
->tmCharSet
;
253 NewTextMetricW2A(NEWTEXTMETRICA
*tma
, NEWTEXTMETRICW
*tmw
)
255 if (! TextMetricW2A((TEXTMETRICA
*) tma
, (TEXTMETRICW
*) tmw
))
260 tma
->ntmFlags
= tmw
->ntmFlags
;
261 tma
->ntmSizeEM
= tmw
->ntmSizeEM
;
262 tma
->ntmCellHeight
= tmw
->ntmCellHeight
;
263 tma
->ntmAvgWidth
= tmw
->ntmAvgWidth
;
269 NewTextMetricExW2A(NEWTEXTMETRICEXA
*tma
, NEWTEXTMETRICEXW
*tmw
)
271 if (! NewTextMetricW2A(&tma
->ntmTm
, &tmw
->ntmTm
))
276 tma
->ntmFontSig
= tmw
->ntmFontSig
;
282 IntEnumFontFamilies(HDC Dc
, LPLOGFONTW LogFont
, PVOID EnumProc
, LPARAM lParam
,
287 PFONTFAMILYINFO Info
;
290 ENUMLOGFONTEXA EnumLogFontExA
;
291 NEWTEXTMETRICEXA NewTextMetricExA
;
293 Info
= RtlAllocateHeap(GetProcessHeap(), 0,
294 INITIAL_FAMILY_COUNT
* sizeof(FONTFAMILYINFO
));
299 FontFamilyCount
= NtGdiGetFontFamilyInfo(Dc
, LogFont
, Info
, INITIAL_FAMILY_COUNT
);
300 if (FontFamilyCount
< 0)
302 RtlFreeHeap(GetProcessHeap(), 0, Info
);
305 if (INITIAL_FAMILY_COUNT
< FontFamilyCount
)
307 FontFamilySize
= FontFamilyCount
;
308 RtlFreeHeap(GetProcessHeap(), 0, Info
);
309 Info
= RtlAllocateHeap(GetProcessHeap(), 0,
310 FontFamilyCount
* sizeof(FONTFAMILYINFO
));
315 FontFamilyCount
= NtGdiGetFontFamilyInfo(Dc
, LogFont
, Info
, FontFamilySize
);
316 if (FontFamilyCount
< 0 || FontFamilySize
< FontFamilyCount
)
318 RtlFreeHeap(GetProcessHeap(), 0, Info
);
323 for (i
= 0; i
< FontFamilyCount
; i
++)
327 Ret
= ((FONTENUMPROCW
) EnumProc
)(
328 (VOID
*)&Info
[i
].EnumLogFontEx
,
329 (VOID
*)&Info
[i
].NewTextMetricEx
,
330 Info
[i
].FontType
, lParam
);
333 { // Could use EnumLogFontExW2A here?
334 LogFontW2A(&EnumLogFontExA
.elfLogFont
, &Info
[i
].EnumLogFontEx
.elfLogFont
);
335 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfFullName
, -1,
336 (LPSTR
)EnumLogFontExA
.elfFullName
, LF_FULLFACESIZE
, NULL
, NULL
);
337 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfStyle
, -1,
338 (LPSTR
)EnumLogFontExA
.elfStyle
, LF_FACESIZE
, NULL
, NULL
);
339 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfScript
, -1,
340 (LPSTR
)EnumLogFontExA
.elfScript
, LF_FACESIZE
, NULL
, NULL
);
341 NewTextMetricExW2A(&NewTextMetricExA
,
342 &Info
[i
].NewTextMetricEx
);
343 Ret
= ((FONTENUMPROCA
) EnumProc
)(
344 (VOID
*)&EnumLogFontExA
,
345 (VOID
*)&NewTextMetricExA
,
346 Info
[i
].FontType
, lParam
);
350 RtlFreeHeap(GetProcessHeap(), 0, Info
);
359 EnumFontFamiliesExW(HDC hdc
, LPLOGFONTW lpLogfont
, FONTENUMPROCW lpEnumFontFamExProc
,
360 LPARAM lParam
, DWORD dwFlags
)
362 return IntEnumFontFamilies(hdc
, lpLogfont
, lpEnumFontFamExProc
, lParam
, TRUE
);
370 EnumFontFamiliesW(HDC hdc
, LPCWSTR lpszFamily
, FONTENUMPROCW lpEnumFontFamProc
,
375 ZeroMemory(&LogFont
, sizeof(LOGFONTW
));
376 LogFont
.lfCharSet
= DEFAULT_CHARSET
;
377 if (NULL
!= lpszFamily
)
379 if (!*lpszFamily
) return 1;
380 lstrcpynW(LogFont
.lfFaceName
, lpszFamily
, LF_FACESIZE
);
383 return IntEnumFontFamilies(hdc
, &LogFont
, lpEnumFontFamProc
, lParam
, TRUE
);
391 EnumFontFamiliesExA (HDC hdc
, LPLOGFONTA lpLogfont
, FONTENUMPROCA lpEnumFontFamExProc
,
392 LPARAM lParam
, DWORD dwFlags
)
394 LOGFONTW LogFontW
, *pLogFontW
;
398 LogFontA2W(&LogFontW
,lpLogfont
);
399 pLogFontW
= &LogFontW
;
401 else pLogFontW
= NULL
;
403 /* no need to convert LogFontW back to lpLogFont b/c it's an [in] parameter only */
404 return IntEnumFontFamilies(hdc
, pLogFontW
, lpEnumFontFamExProc
, lParam
, FALSE
);
412 EnumFontFamiliesA(HDC hdc
, LPCSTR lpszFamily
, FONTENUMPROCA lpEnumFontFamProc
,
417 ZeroMemory(&LogFont
, sizeof(LOGFONTW
));
418 LogFont
.lfCharSet
= DEFAULT_CHARSET
;
419 if (NULL
!= lpszFamily
)
421 if (!*lpszFamily
) return 1;
422 MultiByteToWideChar(CP_THREAD_ACP
, 0, lpszFamily
, -1, LogFont
.lfFaceName
, LF_FACESIZE
);
425 return IntEnumFontFamilies(hdc
, &LogFont
, lpEnumFontFamProc
, lParam
, FALSE
);
434 GetCharacterPlacementA(
439 GCP_RESULTSA
*lpResults
,
444 GCP_RESULTSW resultsW
;
448 if ( !lpString
|| uCount
<= 0 || (nMaxExtent
< 0 && nMaxExtent
!= -1 ) )
450 SetLastError(ERROR_INVALID_PARAMETER
);
453 /* TRACE("%s, %d, %d, 0x%08x\n",
454 debugstr_an(lpString, uCount), uCount, nMaxExtent, dwFlags);
456 /* both structs are equal in size */
457 memcpy(&resultsW
, lpResults
, sizeof(resultsW
));
459 lpStringW
= FONT_mbtowc(hdc
, lpString
, uCount
, &uCountW
, &font_cp
);
460 if(lpResults
->lpOutString
)
461 resultsW
.lpOutString
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*uCountW
);
463 ret
= GetCharacterPlacementW(hdc
, lpStringW
, uCountW
, nMaxExtent
, &resultsW
, dwFlags
);
465 lpResults
->nGlyphs
= resultsW
.nGlyphs
;
466 lpResults
->nMaxFit
= resultsW
.nMaxFit
;
468 if(lpResults
->lpOutString
) {
469 WideCharToMultiByte(font_cp
, 0, resultsW
.lpOutString
, uCountW
,
470 lpResults
->lpOutString
, uCount
, NULL
, NULL
);
473 HeapFree(GetProcessHeap(), 0, lpStringW
);
474 HeapFree(GetProcessHeap(), 0, resultsW
.lpOutString
);
485 GetCharacterPlacementW(
490 GCP_RESULTSW
*lpResults
,
497 DPRINT("GetCharacterPlacementW\n");
499 if(dwFlags
&(~GCP_REORDER
)) DPRINT("flags 0x%08lx ignored\n", dwFlags
);
500 if(lpResults
->lpClass
) DPRINT("classes not implemented\n");
501 if (lpResults
->lpCaretPos
&& (dwFlags
& GCP_REORDER
))
502 DPRINT("Caret positions for complex scripts not implemented\n");
505 if(nSet
> lpResults
->nGlyphs
)
506 nSet
= lpResults
->nGlyphs
;
508 /* return number of initialized fields */
509 lpResults
->nGlyphs
= nSet
;
511 /*if((dwFlags&GCP_REORDER)==0 || !BidiAvail)
513 /* Treat the case where no special handling was requested in a fastpath way */
514 /* copy will do if the GCP_REORDER flag is not set */
515 if(lpResults
->lpOutString
)
516 lstrcpynW( lpResults
->lpOutString
, lpString
, nSet
);
518 if(lpResults
->lpGlyphs
)
519 lstrcpynW( lpResults
->lpGlyphs
, lpString
, nSet
);
521 if(lpResults
->lpOrder
)
523 for(i
= 0; i
< nSet
; i
++)
524 lpResults
->lpOrder
[i
] = i
;
528 BIDI_Reorder( lpString, uCount, dwFlags, WINE_GCPW_FORCE_LTR, lpResults->lpOutString,
529 nSet, lpResults->lpOrder );
532 /* FIXME: Will use the placement chars */
536 for (i
= 0; i
< nSet
; i
++)
538 if (GetCharWidth32W(hdc
, lpString
[i
], lpString
[i
], &c
))
539 lpResults
->lpDx
[i
]= c
;
543 if (lpResults
->lpCaretPos
&& !(dwFlags
& GCP_REORDER
))
547 lpResults
->lpCaretPos
[0] = 0;
548 for (i
= 1; i
< nSet
; i
++)
549 if (GetTextExtentPoint32W(hdc
, &(lpString
[i
- 1]), 1, &size
))
550 lpResults
->lpCaretPos
[i
] = (pos
+= size
.cx
);
553 /*if(lpResults->lpGlyphs)
554 NtGdiGetGlyphIndicesW(hdc, lpString, nSet, lpResults->lpGlyphs, 0);*/
556 if (GetTextExtentPoint32W(hdc
, lpString
, uCount
, &size
))
557 ret
= MAKELONG(size
.cx
, size
.cy
);
564 NewGetCharacterPlacementW(
569 GCP_RESULTSW
*lpResults
,
576 if ( !lpString
|| uCount
<= 0 || (nMaxExtent
< 0 && nMaxExtent
!= -1 ) )
578 SetLastError(ERROR_INVALID_PARAMETER
);
584 if ( GetTextExtentPointW(hdc
, lpString
, uCount
, &Size
) )
586 return MAKELONG(Size
.cx
, Size
.cy
);
592 if ( nSet
> lpResults
->nGlyphs
)
593 nSet
= lpResults
->nGlyphs
;
595 return NtGdiGetCharacterPlacementW( hdc
,
609 GetCharABCWidthsFloatW(HDC hdc
,
614 DPRINT("GetCharABCWidthsFloatW\n");
615 if ((!abcF
) || (FirstChar
> LastChar
))
617 SetLastError(ERROR_INVALID_PARAMETER
);
620 return NtGdiGetCharABCWidthsW( hdc
,
622 (ULONG
)(LastChar
- FirstChar
+ 1),
634 GetCharWidthFloatW(HDC hdc
,
639 DPRINT("GetCharWidthsFloatW\n");
640 if ((!pxBuffer
) || (iFirstChar
> iLastChar
))
642 SetLastError(ERROR_INVALID_PARAMETER
);
645 return NtGdiGetCharWidthW( hdc
,
647 (ULONG
)(iLastChar
- iFirstChar
+ 1),
659 GetCharWidthW(HDC hdc
,
664 DPRINT("GetCharWidthsW\n");
665 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
667 SetLastError(ERROR_INVALID_PARAMETER
);
670 return NtGdiGetCharWidthW( hdc
,
672 (ULONG
)(iLastChar
- iFirstChar
+ 1),
684 GetCharWidth32W(HDC hdc
,
689 DPRINT("GetCharWidths32W\n");
690 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
692 SetLastError(ERROR_INVALID_PARAMETER
);
695 return NtGdiGetCharWidthW( hdc
,
697 (ULONG
)(iLastChar
- iFirstChar
+ 1),
699 GCW_NOFLOAT
|GCW_WIN32
,
710 GetCharABCWidthsW(HDC hdc
,
715 DPRINT("GetCharABCWidthsW\n");
716 if ((!lpabc
) || (FirstChar
> LastChar
))
718 SetLastError(ERROR_INVALID_PARAMETER
);
721 return NtGdiGetCharABCWidthsW( hdc
,
723 (ULONG
)(LastChar
- FirstChar
+ 1),
741 INT i
, wlen
, count
= (INT
)(iLastChar
- iFirstChar
+ 1);
746 DPRINT("GetCharWidthsA\n");
747 if(count
<= 0) return FALSE
;
749 str
= HeapAlloc(GetProcessHeap(), 0, count
+1);
753 for(i
= 0; i
< count
; i
++)
754 str
[i
] = (BYTE
)(iFirstChar
+ i
);
757 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
760 HeapFree(GetProcessHeap(), 0, str
);
764 ret
= NtGdiGetCharWidthW( hdc
,
771 HeapFree(GetProcessHeap(), 0, str
);
772 HeapFree(GetProcessHeap(), 0, wstr
);
789 INT i
, wlen
, count
= (INT
)(iLastChar
- iFirstChar
+ 1);
794 DPRINT("GetCharWidths32A\n");
795 if(count
<= 0) return FALSE
;
797 str
= HeapAlloc(GetProcessHeap(), 0, count
+1);
800 for(i
= 0; i
< count
; i
++)
801 str
[i
] = (BYTE
)(iFirstChar
+ i
);
804 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
807 HeapFree(GetProcessHeap(), 0, str
);
811 ret
= NtGdiGetCharWidthW( hdc
,
815 GCW_NOFLOAT
|GCW_WIN32
,
818 HeapFree(GetProcessHeap(), 0, str
);
819 HeapFree(GetProcessHeap(), 0, wstr
);
836 INT i
, wlen
, count
= (INT
)(iLastChar
- iFirstChar
+ 1);
841 DPRINT("GetCharWidthsFloatA\n");
842 if(count
<= 0) return FALSE
;
844 str
= HeapAlloc(GetProcessHeap(), 0, count
+1);
847 for(i
= 0; i
< count
; i
++)
848 str
[i
] = (BYTE
)(iFirstChar
+ i
);
851 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
854 HeapFree(GetProcessHeap(), 0, str
);
857 ret
= NtGdiGetCharWidthW( hdc
, wstr
[0], (ULONG
) count
, (PWCHAR
) wstr
, 0, (PVOID
) pxBuffer
);
859 HeapFree(GetProcessHeap(), 0, str
);
860 HeapFree(GetProcessHeap(), 0, wstr
);
877 INT i
, wlen
, count
= (INT
)(uLastChar
- uFirstChar
+ 1);
882 DPRINT("GetCharABCWidthsA\n");
883 if(count
<= 0) return FALSE
;
885 str
= HeapAlloc(GetProcessHeap(), 0, count
+1);
888 for(i
= 0; i
< count
; i
++)
889 str
[i
] = (BYTE
)(uFirstChar
+ i
);
892 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
895 HeapFree(GetProcessHeap(), 0, str
);
899 ret
= NtGdiGetCharABCWidthsW( hdc
,
906 HeapFree(GetProcessHeap(), 0, str
);
907 HeapFree(GetProcessHeap(), 0, wstr
);
917 GetCharABCWidthsFloatA(
924 INT i
, wlen
, count
= (INT
)(iLastChar
- iFirstChar
+ 1);
929 DPRINT("GetCharABCWidthsFloatA\n");
930 if (count
<= 0) return FALSE
;
932 str
= HeapAlloc(GetProcessHeap(), 0, count
+1);
936 for(i
= 0; i
< count
; i
++)
937 str
[i
] = (BYTE
)(iFirstChar
+ i
);
940 wstr
= FONT_mbtowc( hdc
, str
, count
+1, &wlen
, NULL
);
943 HeapFree( GetProcessHeap(), 0, str
);
946 ret
= NtGdiGetCharABCWidthsW( hdc
,wstr
[0],(ULONG
)count
, (PWCHAR
)wstr
, 0, (PVOID
)lpABCF
);
948 HeapFree( GetProcessHeap(), 0, str
);
949 HeapFree( GetProcessHeap(), 0, wstr
);
959 GetCharABCWidthsI(HDC hdc
,
965 DPRINT("GetCharABCWidthsI\n");
966 return NtGdiGetCharABCWidthsW( hdc
,
970 GCABCW_NOFLOAT
|GCABCW_INDICES
,
979 GetCharWidthI(HDC hdc
,
986 DPRINT("GetCharWidthsI\n");
987 if (!lpBuffer
|| (!pgi
&& (giFirst
== MAXUSHORT
))) // Cannot be at max.
989 SetLastError(ERROR_INVALID_PARAMETER
);
992 if (!cgi
) return TRUE
;
993 return NtGdiGetCharWidthW( hdc
,
997 GCW_INDICES
|GCW_NOFLOAT
|GCW_WIN32
,
1006 GetFontLanguageInfo(
1010 DWORD Gcp
= 0, Ret
= 0;
1013 Ret
= NtGdiGetTextCharsetInfo(hDc
, NULL
, 0);
1014 if ((Ret
== ARABIC_CHARSET
) || (Ret
== HEBREW_CHARSET
))
1015 Ret
= (GCP_KASHIDA
|GCP_DIACRITIC
|GCP_LIGATE
|GCP_GLYPHSHAPE
|GCP_REORDER
);
1017 Gcp
= GetDCDWord(hDc
, GdiGetFontLanguageInfo
, GCP_ERROR
);
1018 if ( Gcp
== GCP_ERROR
)
1042 lpstrW
= FONT_mbtowc(hdc
, lpstr
, count
, &countW
, NULL
);
1043 Ret
= NtGdiGetGlyphIndicesW(hdc
, lpstrW
, countW
, pgi
, flags
);
1044 HeapFree(GetProcessHeap(), 0, lpstrW
);
1057 LPGLYPHMETRICS lpgm
,
1067 DPRINT("GetGlyphOutlineA uChar %x\n", uChar
);
1068 if(!(uFormat
& GGO_GLYPH_INDEX
)) {
1071 if(uChar
> 0xff) { /* but, 2 bytes character only */
1073 mbchs
[0] = (uChar
& 0xff00) >> 8;
1074 mbchs
[1] = (uChar
& 0xff);
1077 mbchs
[0] = (uChar
& 0xff);
1079 p
= FONT_mbtowc(hdc
, mbchs
, len
, NULL
, NULL
);
1083 ret
= NtGdiGetGlyphOutline(hdc
, c
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1084 HeapFree(GetProcessHeap(), 0, p
);
1098 LPGLYPHMETRICS lpgm
,
1104 DPRINT("GetGlyphOutlineW uChar %x\n", uChar
);
1105 if (!lpgm
& !lpmat2
) return GDI_ERROR
;
1106 if (!lpvBuffer
) cbBuffer
= 0;
1107 return NtGdiGetGlyphOutline ( hdc
, uChar
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1116 GetOutlineTextMetricsA(
1119 LPOUTLINETEXTMETRICA lpOTM
1122 char buf
[512], *ptr
;
1124 OUTLINETEXTMETRICW
*lpOTMW
= (OUTLINETEXTMETRICW
*)buf
;
1125 OUTLINETEXTMETRICA
*output
= lpOTM
;
1128 if((ret
= GetOutlineTextMetricsW(hdc
, 0, NULL
)) == 0)
1130 if(ret
> sizeof(buf
))
1131 lpOTMW
= HeapAlloc(GetProcessHeap(), 0, ret
);
1132 GetOutlineTextMetricsW(hdc
, ret
, lpOTMW
);
1134 needed
= sizeof(OUTLINETEXTMETRICA
);
1135 if(lpOTMW
->otmpFamilyName
)
1136 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1137 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1138 NULL
, 0, NULL
, NULL
);
1139 if(lpOTMW
->otmpFaceName
)
1140 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1141 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1142 NULL
, 0, NULL
, NULL
);
1143 if(lpOTMW
->otmpStyleName
)
1144 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1145 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1146 NULL
, 0, NULL
, NULL
);
1147 if(lpOTMW
->otmpFullName
)
1148 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1149 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1150 NULL
, 0, NULL
, NULL
);
1157 DPRINT("needed = %d\n", needed
);
1159 /* Since the supplied buffer isn't big enough, we'll alloc one
1160 that is and memcpy the first cbData bytes into the lpOTM at
1162 output
= HeapAlloc(GetProcessHeap(), 0, needed
);
1164 ret
= output
->otmSize
= min(needed
, cbData
);
1165 FONT_TextMetricWToA( &lpOTMW
->otmTextMetrics
, &output
->otmTextMetrics
);
1166 output
->otmFiller
= 0;
1167 output
->otmPanoseNumber
= lpOTMW
->otmPanoseNumber
;
1168 output
->otmfsSelection
= lpOTMW
->otmfsSelection
;
1169 output
->otmfsType
= lpOTMW
->otmfsType
;
1170 output
->otmsCharSlopeRise
= lpOTMW
->otmsCharSlopeRise
;
1171 output
->otmsCharSlopeRun
= lpOTMW
->otmsCharSlopeRun
;
1172 output
->otmItalicAngle
= lpOTMW
->otmItalicAngle
;
1173 output
->otmEMSquare
= lpOTMW
->otmEMSquare
;
1174 output
->otmAscent
= lpOTMW
->otmAscent
;
1175 output
->otmDescent
= lpOTMW
->otmDescent
;
1176 output
->otmLineGap
= lpOTMW
->otmLineGap
;
1177 output
->otmsCapEmHeight
= lpOTMW
->otmsCapEmHeight
;
1178 output
->otmsXHeight
= lpOTMW
->otmsXHeight
;
1179 output
->otmrcFontBox
= lpOTMW
->otmrcFontBox
;
1180 output
->otmMacAscent
= lpOTMW
->otmMacAscent
;
1181 output
->otmMacDescent
= lpOTMW
->otmMacDescent
;
1182 output
->otmMacLineGap
= lpOTMW
->otmMacLineGap
;
1183 output
->otmusMinimumPPEM
= lpOTMW
->otmusMinimumPPEM
;
1184 output
->otmptSubscriptSize
= lpOTMW
->otmptSubscriptSize
;
1185 output
->otmptSubscriptOffset
= lpOTMW
->otmptSubscriptOffset
;
1186 output
->otmptSuperscriptSize
= lpOTMW
->otmptSuperscriptSize
;
1187 output
->otmptSuperscriptOffset
= lpOTMW
->otmptSuperscriptOffset
;
1188 output
->otmsStrikeoutSize
= lpOTMW
->otmsStrikeoutSize
;
1189 output
->otmsStrikeoutPosition
= lpOTMW
->otmsStrikeoutPosition
;
1190 output
->otmsUnderscoreSize
= lpOTMW
->otmsUnderscoreSize
;
1191 output
->otmsUnderscorePosition
= lpOTMW
->otmsUnderscorePosition
;
1194 ptr
= (char*)(output
+ 1);
1195 left
= needed
- sizeof(*output
);
1197 if(lpOTMW
->otmpFamilyName
) {
1198 output
->otmpFamilyName
= (LPSTR
)(ptr
- (char*)output
);
1199 len
= WideCharToMultiByte(CP_ACP
, 0,
1200 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1201 ptr
, left
, NULL
, NULL
);
1205 output
->otmpFamilyName
= 0;
1207 if(lpOTMW
->otmpFaceName
) {
1208 output
->otmpFaceName
= (LPSTR
)(ptr
- (char*)output
);
1209 len
= WideCharToMultiByte(CP_ACP
, 0,
1210 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1211 ptr
, left
, NULL
, NULL
);
1215 output
->otmpFaceName
= 0;
1217 if(lpOTMW
->otmpStyleName
) {
1218 output
->otmpStyleName
= (LPSTR
)(ptr
- (char*)output
);
1219 len
= WideCharToMultiByte(CP_ACP
, 0,
1220 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1221 ptr
, left
, NULL
, NULL
);
1225 output
->otmpStyleName
= 0;
1227 if(lpOTMW
->otmpFullName
) {
1228 output
->otmpFullName
= (LPSTR
)(ptr
- (char*)output
);
1229 len
= WideCharToMultiByte(CP_ACP
, 0,
1230 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1231 ptr
, left
, NULL
, NULL
);
1234 output
->otmpFullName
= 0;
1238 if(output
!= lpOTM
) {
1239 memcpy(lpOTM
, output
, cbData
);
1240 HeapFree(GetProcessHeap(), 0, output
);
1242 /* check if the string offsets really fit into the provided size */
1243 /* FIXME: should we check string length as well? */
1244 if ((UINT_PTR
)lpOTM
->otmpFamilyName
>= lpOTM
->otmSize
)
1245 lpOTM
->otmpFamilyName
= 0; /* doesn't fit */
1247 if ((UINT_PTR
)lpOTM
->otmpFaceName
>= lpOTM
->otmSize
)
1248 lpOTM
->otmpFaceName
= 0; /* doesn't fit */
1250 if ((UINT_PTR
)lpOTM
->otmpStyleName
>= lpOTM
->otmSize
)
1251 lpOTM
->otmpStyleName
= 0; /* doesn't fit */
1253 if ((UINT_PTR
)lpOTM
->otmpFullName
>= lpOTM
->otmSize
)
1254 lpOTM
->otmpFullName
= 0; /* doesn't fit */
1258 if(lpOTMW
!= (OUTLINETEXTMETRICW
*)buf
)
1259 HeapFree(GetProcessHeap(), 0, lpOTMW
);
1270 GetOutlineTextMetricsW(
1273 LPOUTLINETEXTMETRICW lpOTM
1276 TMDIFF Tmd
; // Should not be zero.
1278 return NtGdiGetOutlineTextMetricsInternalW(hdc
, cbData
, lpOTM
, &Tmd
);
1286 GetKerningPairsW(HDC hdc
,
1288 LPKERNINGPAIR pkpDst
)
1290 if ((cPairs
!= 0) || (pkpDst
== 0))
1292 return NtGdiGetKerningPairs(hdc
,cPairs
,pkpDst
);
1296 SetLastError(ERROR_INVALID_PARAMETER
);
1306 GetKerningPairsA( HDC hDC
,
1308 LPKERNINGPAIR kern_pairA
)
1313 DWORD i
, total_kern_pairs
, kern_pairs_copied
= 0;
1314 KERNINGPAIR
*kern_pairW
;
1316 if (!cPairs
&& kern_pairA
)
1318 SetLastError(ERROR_INVALID_PARAMETER
);
1322 charset
= GetTextCharset(hDC
);
1323 if (!TranslateCharsetInfo(ULongToPtr(charset
), &csi
, TCI_SRCCHARSET
))
1325 DPRINT1("Can't find codepage for charset %d\n", charset
);
1328 /* GetCPInfo() will fail on CP_SYMBOL, and WideCharToMultiByte is supposed
1329 * to fail on an invalid character for CP_SYMBOL.
1331 cpi
.DefaultChar
[0] = 0;
1332 if (csi
.ciACP
!= CP_SYMBOL
&& !GetCPInfo(csi
.ciACP
, &cpi
))
1334 DPRINT1("Can't find codepage %u info\n", csi
.ciACP
);
1337 DPRINT("charset %d => codepage %u\n", charset
, csi
.ciACP
);
1339 total_kern_pairs
= NtGdiGetKerningPairs(hDC
, 0, NULL
);
1340 if (!total_kern_pairs
) return 0;
1342 if (!cPairs
&& !kern_pairA
) return total_kern_pairs
;
1344 kern_pairW
= HeapAlloc(GetProcessHeap(), 0, total_kern_pairs
* sizeof(*kern_pairW
));
1345 GetKerningPairsW(hDC
, total_kern_pairs
, kern_pairW
);
1347 for (i
= 0; i
< total_kern_pairs
; i
++)
1351 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wFirst
, 1, &first
, 1, NULL
, NULL
))
1354 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wSecond
, 1, &second
, 1, NULL
, NULL
))
1357 if (first
== cpi
.DefaultChar
[0] || second
== cpi
.DefaultChar
[0])
1362 if (kern_pairs_copied
>= cPairs
) break;
1364 kern_pairA
->wFirst
= (BYTE
)first
;
1365 kern_pairA
->wSecond
= (BYTE
)second
;
1366 kern_pairA
->iKernAmount
= kern_pairW
[i
].iKernAmount
;
1369 kern_pairs_copied
++;
1372 HeapFree(GetProcessHeap(), 0, kern_pairW
);
1374 return kern_pairs_copied
;
1384 CreateFontIndirectExA(const ENUMLOGFONTEXDVA
*elfexd
)
1388 ENUMLOGFONTEXDVW Logfont
;
1390 EnumLogFontExW2A( (LPENUMLOGFONTEXA
) elfexd
,
1391 &Logfont
.elfEnumLogfontEx
);
1393 RtlCopyMemory( &Logfont
.elfDesignVector
,
1394 (PVOID
) &elfexd
->elfDesignVector
,
1395 sizeof(DESIGNVECTOR
));
1397 return NtGdiHfontCreate( &Logfont
, 0, 0, 0, NULL
);
1408 CreateFontIndirectExW(const ENUMLOGFONTEXDVW
*elfexd
)
1410 /* Msdn: Note, this function ignores the elfDesignVector member in
1415 return NtGdiHfontCreate((PENUMLOGFONTEXDVW
) elfexd
, 0, 0, 0, NULL
);
1426 CreateFontIndirectA(
1427 CONST LOGFONTA
*lplf
1434 LogFontA2W(&tlf
, lplf
);
1435 return CreateFontIndirectW(&tlf
);
1446 CreateFontIndirectW(
1447 CONST LOGFONTW
*lplf
1452 ENUMLOGFONTEXDVW Logfont
;
1454 RtlCopyMemory( &Logfont
.elfEnumLogfontEx
.elfLogFont
, lplf
, sizeof(LOGFONTW
));
1455 // Need something other than just cleaning memory here.
1456 // Guess? Use caller data to determine the rest.
1457 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfFullName
,
1458 sizeof(Logfont
.elfEnumLogfontEx
.elfFullName
));
1459 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfStyle
,
1460 sizeof(Logfont
.elfEnumLogfontEx
.elfStyle
));
1461 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfScript
,
1462 sizeof(Logfont
.elfEnumLogfontEx
.elfScript
));
1464 Logfont
.elfDesignVector
.dvNumAxes
= 0; // No more than MM_MAX_NUMAXES
1466 RtlZeroMemory( &Logfont
.elfDesignVector
, sizeof(DESIGNVECTOR
));
1468 return CreateFontIndirectExW(&Logfont
);
1489 DWORD fdwOutputPrecision
,
1490 DWORD fdwClipPrecision
,
1492 DWORD fdwPitchAndFamily
,
1496 ANSI_STRING StringA
;
1497 UNICODE_STRING StringU
;
1500 RtlInitAnsiString(&StringA
, (LPSTR
)lpszFace
);
1501 RtlAnsiStringToUnicodeString(&StringU
, &StringA
, TRUE
);
1503 ret
= CreateFontW(nHeight
,
1518 RtlFreeUnicodeString(&StringU
);
1539 DWORD fdwOutputPrecision
,
1540 DWORD fdwClipPrecision
,
1542 DWORD fdwPitchAndFamily
,
1548 logfont
.lfHeight
= nHeight
;
1549 logfont
.lfWidth
= nWidth
;
1550 logfont
.lfEscapement
= nEscapement
;
1551 logfont
.lfOrientation
= nOrientation
;
1552 logfont
.lfWeight
= nWeight
;
1553 logfont
.lfItalic
= fnItalic
;
1554 logfont
.lfUnderline
= fdwUnderline
;
1555 logfont
.lfStrikeOut
= fdwStrikeOut
;
1556 logfont
.lfCharSet
= fdwCharSet
;
1557 logfont
.lfOutPrecision
= fdwOutputPrecision
;
1558 logfont
.lfClipPrecision
= fdwClipPrecision
;
1559 logfont
.lfQuality
= fdwQuality
;
1560 logfont
.lfPitchAndFamily
= fdwPitchAndFamily
;
1562 if (NULL
!= lpszFace
)
1564 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
1565 wcsncpy((wchar_t *)logfont
.lfFaceName
, lpszFace
, Size
- 1);
1566 /* Be 101% sure to have '\0' at end of string */
1567 logfont
.lfFaceName
[Size
- 1] = '\0';
1571 logfont
.lfFaceName
[0] = L
'\0';
1574 return CreateFontIndirectW(&logfont
);
1583 CreateScalableFontResourceA(
1586 LPCSTR lpszFontFile
,
1587 LPCSTR lpszCurrentPath
1599 AddFontResourceExW ( LPCWSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1601 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1603 SetLastError( ERROR_INVALID_PARAMETER
);
1607 return GdiAddFontResourceW(lpszFilename
, fl
,0);
1616 AddFontResourceExA ( LPCSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1622 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1624 SetLastError( ERROR_INVALID_PARAMETER
);
1628 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1629 if ( !NT_SUCCESS (Status
) )
1631 SetLastError (RtlNtStatusToDosError(Status
));
1635 rc
= GdiAddFontResourceW ( FilenameW
, fl
, 0 );
1636 HEAP_free ( FilenameW
);
1646 AddFontResourceA ( LPCSTR lpszFilename
)
1652 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1653 if ( !NT_SUCCESS (Status
) )
1655 SetLastError (RtlNtStatusToDosError(Status
));
1659 rc
= GdiAddFontResourceW ( FilenameW
, 0, 0);
1661 HEAP_free ( FilenameW
);
1672 AddFontResourceW ( LPCWSTR lpszFilename
)
1674 return GdiAddFontResourceW ( lpszFilename
, 0, 0 );
1683 RemoveFontResourceW(LPCWSTR lpFileName
)
1685 return RemoveFontResourceExW(lpFileName
,0,0);
1694 RemoveFontResourceA(LPCSTR lpFileName
)
1696 return RemoveFontResourceExA(lpFileName
,0,0);
1704 RemoveFontResourceExA(LPCSTR lpFileName
,
1712 /* FIXME the flags */
1714 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1716 Status
= HEAP_strdupA2W ( &lpFileNameW
, lpFileName
);
1717 if (!NT_SUCCESS (Status
))
1718 SetLastError (RtlNtStatusToDosError(Status
));
1722 HEAP_free ( lpFileNameW
);
1733 RemoveFontResourceExW(LPCWSTR lpFileName
,
1737 /* FIXME the flags */
1739 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1744 /***********************************************************************
1745 * GdiGetCharDimensions
1747 * Gets the average width of the characters in the English alphabet.
1750 * hdc [I] Handle to the device context to measure on.
1751 * lptm [O] Pointer to memory to store the text metrics into.
1752 * height [O] On exit, the maximum height of characters in the English alphabet.
1755 * The average width of characters in the English alphabet.
1758 * This function is used by the dialog manager to get the size of a dialog
1759 * unit. It should also be used by other pieces of code that need to know
1760 * the size of a dialog unit in logical units without having access to the
1761 * window handle of the dialog.
1762 * Windows caches the font metrics from this function, but we don't and
1763 * there doesn't appear to be an immediate advantage to do so.
1766 * GetTextExtentPointW, GetTextMetricsW, MapDialogRect.
1768 * Despite most of MSDN insisting that the horizontal base unit is
1769 * tmAveCharWidth it isn't. Knowledge base article Q145994
1770 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
1771 * says that we should take the average of the 52 English upper and lower
1779 GdiGetCharDimensions(HDC hdc
, LPTEXTMETRICW lptm
, LONG
*height
)
1783 static const WCHAR alphabet
[] = {
1784 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
1785 'r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H',
1786 'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',0};
1788 if(!GetTextMetricsW(hdc
, &tm
)) return 0;
1790 if(!GetTextExtentPointW(hdc
, alphabet
, 52, &sz
)) return 0;
1792 if (lptm
) *lptm
= tm
;
1793 if (height
) *height
= tm
.tmHeight
;
1795 return (sz
.cx
/ 26 + 1) / 2;
1798 /*************************************************************************
1799 * TranslateCharsetInfo [GDI32.@]
1801 * Fills a CHARSETINFO structure for a character set, code page, or
1802 * font. This allows making the correspondance between different labelings
1803 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1804 * of the same encoding.
1806 * Only one codepage will be set in lpCs->fs. If TCI_SRCFONTSIG is used,
1807 * only one codepage should be set in *lpSrc.
1810 * TRUE on success, FALSE on failure.
1818 TranslateCharsetInfo(
1819 LPDWORD lpSrc
, /* [in]
1820 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1821 if flags == TCI_SRCCHARSET: a character set value
1822 if flags == TCI_SRCCODEPAGE: a code page value
1824 LPCHARSETINFO lpCs
, /* [out] structure to receive charset information */
1825 DWORD flags
/* [in] determines interpretation of lpSrc */)
1829 case TCI_SRCFONTSIG
:
1830 while (!(*lpSrc
>>index
& 0x0001) && index
<MAXTCIINDEX
) index
++;
1832 case TCI_SRCCODEPAGE
:
1833 while (PtrToUlong(lpSrc
) != FONT_tci
[index
].ciACP
&& index
< MAXTCIINDEX
) index
++;
1835 case TCI_SRCCHARSET
:
1836 while (PtrToUlong(lpSrc
) != FONT_tci
[index
].ciCharset
&& index
< MAXTCIINDEX
) index
++;
1841 if (index
>= MAXTCIINDEX
|| FONT_tci
[index
].ciCharset
== DEFAULT_CHARSET
) return FALSE
;
1842 memcpy(lpCs
, &FONT_tci
[index
], sizeof(CHARSETINFO
));
1857 DWORD Ret
= GDI_ERROR
;
1860 if (GDI_HANDLE_GET_TYPE(hDC
) != GDI_OBJECT_TYPE_DC
)
1862 if (GDI_HANDLE_GET_TYPE(hDC
) == GDI_OBJECT_TYPE_METADC
)
1863 return MFDRV_SetMapperFlags( hDC
, flags
);
1866 PLDC pLDC
= Dc_Attr
->pvLDC
;
1869 SetLastError(ERROR_INVALID_HANDLE
);
1872 if (pLDC
->iType
== LDC_EMFLDC
)
1874 return EMFDRV_SetMapperFlags( hDC
, flags
);
1879 if (!GdiGetHandleUserData((HGDIOBJ
) hDC
, GDI_OBJECT_TYPE_DC
, (PVOID
) &Dc_Attr
)) return GDI_ERROR
;
1881 if (NtCurrentTeb()->GdiTebBatch
.HDC
== hDC
)
1883 if (Dc_Attr
->ulDirty_
& DC_FONTTEXT_DIRTY
)
1886 Dc_Attr
->ulDirty_
&= ~(DC_MODE_DIRTY
|DC_FONTTEXT_DIRTY
);
1891 SetLastError(ERROR_INVALID_PARAMETER
);
1894 Ret
= Dc_Attr
->flFontMapper
;
1895 Dc_Attr
->flFontMapper
= flags
;
1909 FONTENUMPROCW FontFunc
,
1914 return NtGdiEnumFonts ( hDC
, lpFaceName
, FontFunc
, lParam
);
1916 return EnumFontFamiliesW( hDC
, lpFaceName
, FontFunc
, lParam
);
1928 FONTENUMPROCA FontFunc
,
1937 Status
= HEAP_strdupA2W ( &lpFaceNameW
, lpFaceName
);
1938 if (!NT_SUCCESS (Status
))
1939 SetLastError (RtlNtStatusToDosError(Status
));
1942 rc
= NtGdiEnumFonts ( hDC
, lpFaceNameW
, FontFunc
, lParam
);
1944 HEAP_free ( lpFaceNameW
);
1948 return EnumFontFamiliesA( hDC
, lpFaceName
, FontFunc
, lParam
);
1952 #define EfdFontFamilies 3
1956 NewEnumFontFamiliesExW(
1958 LPLOGFONTW lpLogfont
,
1959 FONTENUMPROCW lpEnumFontFamExProcW
,
1963 ULONG_PTR idEnum
, cbDataSize
, cbRetSize
;
1964 PENUMFONTDATAW pEfdw
;
1969 /* Open enumeration handle and find out how much memory we need */
1970 idEnum
= NtGdiEnumFontOpen(hDC
,
1974 (lpLogfont
&& lpLogfont
->lfFaceName
[0])? lpLogfont
->lfFaceName
: NULL
,
1975 lpLogfont
? lpLogfont
->lfCharSet
: DEFAULT_CHARSET
,
1981 if (cbDataSize
== 0)
1983 NtGdiEnumFontClose(idEnum
);
1987 /* Allocate memory */
1988 pBuffer
= HeapAlloc(GetProcessHeap(), 0, cbDataSize
);
1989 if (pBuffer
== NULL
)
1991 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1992 NtGdiEnumFontClose(idEnum
);
1996 /* Do the enumeration */
1997 if (!NtGdiEnumFontChunk(hDC
, idEnum
, cbDataSize
, &cbRetSize
, (PVOID
)pBuffer
))
1999 HeapFree(GetProcessHeap(), 0, pBuffer
);
2000 NtGdiEnumFontClose(idEnum
);
2004 /* Get start and end address */
2005 pEfdw
= (PENUMFONTDATAW
)pBuffer
;
2006 pMax
= pBuffer
+ cbDataSize
;
2008 /* Iterate through the structures */
2009 while ((PBYTE
)pEfdw
< pMax
&& ret
)
2011 PNTMW_INTERNAL pNtmwi
= (PNTMW_INTERNAL
)((ULONG_PTR
)pEfdw
+ pEfdw
->ulNtmwiOffset
);
2013 ret
= lpEnumFontFamExProcW((VOID
*)&pEfdw
->elfexdv
.elfEnumLogfontEx
,
2014 (VOID
*)&pNtmwi
->ntmw
,
2018 pEfdw
= (PENUMFONTDATAW
)((ULONG_PTR
)pEfdw
+ pEfdw
->cbSize
);
2021 /* Release the memory and close handle */
2022 HeapFree(GetProcessHeap(), 0, pBuffer
);
2023 NtGdiEnumFontClose(idEnum
);