2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: win32ss/gdi/gdi32/objects/font.c
18 /* Rounds a floating point number to integer. The world-to-viewport
19 * transformation process is done in floating point internally. This function
20 * is then used to round these coordinates to integer values.
22 static __inline INT
GDI_ROUND(FLOAT val
)
24 return (int)floor(val
+ 0.5);
28 * For TranslateCharsetInfo
30 #define MAXTCIINDEX 32
31 static const CHARSETINFO FONT_tci
[MAXTCIINDEX
] =
34 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
35 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
36 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
37 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
38 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
39 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
40 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
41 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
42 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
43 /* reserved by ANSI */
44 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
45 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
46 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
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}} },
52 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
53 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
54 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
55 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
56 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
57 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
58 /* reserved for alternate ANSI and OEM */
59 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
60 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
61 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
62 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
63 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
64 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
65 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
66 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
67 /* reserved for system */
68 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
69 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
72 #define INITIAL_FAMILY_COUNT 64
74 /***********************************************************************
75 * TEXTMETRIC conversion functions.
79 FONT_TextMetricWToA(const TEXTMETRICW
*ptmW
, LPTEXTMETRICA ptmA
)
81 ptmA
->tmHeight
= ptmW
->tmHeight
;
82 ptmA
->tmAscent
= ptmW
->tmAscent
;
83 ptmA
->tmDescent
= ptmW
->tmDescent
;
84 ptmA
->tmInternalLeading
= ptmW
->tmInternalLeading
;
85 ptmA
->tmExternalLeading
= ptmW
->tmExternalLeading
;
86 ptmA
->tmAveCharWidth
= ptmW
->tmAveCharWidth
;
87 ptmA
->tmMaxCharWidth
= ptmW
->tmMaxCharWidth
;
88 ptmA
->tmWeight
= ptmW
->tmWeight
;
89 ptmA
->tmOverhang
= ptmW
->tmOverhang
;
90 ptmA
->tmDigitizedAspectX
= ptmW
->tmDigitizedAspectX
;
91 ptmA
->tmDigitizedAspectY
= ptmW
->tmDigitizedAspectY
;
92 ptmA
->tmFirstChar
= min(ptmW
->tmFirstChar
, 255);
93 if (ptmW
->tmCharSet
== SYMBOL_CHARSET
)
95 ptmA
->tmFirstChar
= 0x1e;
96 ptmA
->tmLastChar
= 0xff; /* win9x behaviour - we need the OS2 table data to calculate correctly */
100 ptmA
->tmFirstChar
= ptmW
->tmDefaultChar
- 1;
101 ptmA
->tmLastChar
= min(ptmW
->tmLastChar
, 0xff);
103 ptmA
->tmDefaultChar
= (CHAR
)ptmW
->tmDefaultChar
;
104 ptmA
->tmBreakChar
= (CHAR
)ptmW
->tmBreakChar
;
105 ptmA
->tmItalic
= ptmW
->tmItalic
;
106 ptmA
->tmUnderlined
= ptmW
->tmUnderlined
;
107 ptmA
->tmStruckOut
= ptmW
->tmStruckOut
;
108 ptmA
->tmPitchAndFamily
= ptmW
->tmPitchAndFamily
;
109 ptmA
->tmCharSet
= ptmW
->tmCharSet
;
112 /***********************************************************************
115 * Returns a Unicode translation of str using the charset of the
116 * currently selected font in hdc. If count is -1 then str is assumed
117 * to be '\0' terminated, otherwise it contains the number of bytes to
118 * convert. If plenW is non-NULL, on return it will point to the
119 * number of WCHARs that have been written. If pCP is non-NULL, on
120 * return it will point to the codepage used in the conversion. The
121 * caller should free the returned LPWSTR from the process heap
124 static LPWSTR
FONT_mbtowc(HDC hdc
, LPCSTR str
, INT count
, INT
*plenW
, UINT
*pCP
)
126 UINT cp
= GdiGetCodePage( hdc
);
130 if(count
== -1) count
= strlen(str
);
131 lenW
= MultiByteToWideChar(cp
, 0, str
, count
, NULL
, 0);
132 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
*sizeof(WCHAR
));
135 MultiByteToWideChar(cp
, 0, str
, count
, strW
, lenW
);
136 DPRINT("mapped %s -> %S\n", str
, strW
);
137 if(plenW
) *plenW
= lenW
;
142 static LPSTR
FONT_GetCharsByRangeA(HDC hdc
, UINT firstChar
, UINT lastChar
, PINT pByteLen
)
144 INT i
, count
= lastChar
- firstChar
+ 1;
151 switch (GdiGetCodePage(hdc
))
158 if (lastChar
> 0xffff)
160 if ((firstChar
^ lastChar
) > 0xff)
169 str
= HeapAlloc(GetProcessHeap(), 0, count
* 2 + 1);
173 for(i
= 0, c
= firstChar
; c
<= lastChar
; i
++, c
++)
176 str
[i
++] = (BYTE
)(c
>> 8);
187 NewTextMetricW2A(NEWTEXTMETRICA
*tma
, NEWTEXTMETRICW
*tmw
)
189 FONT_TextMetricWToA((TEXTMETRICW
*) tmw
, (TEXTMETRICA
*) tma
);
190 tma
->ntmFlags
= tmw
->ntmFlags
;
191 tma
->ntmSizeEM
= tmw
->ntmSizeEM
;
192 tma
->ntmCellHeight
= tmw
->ntmCellHeight
;
193 tma
->ntmAvgWidth
= tmw
->ntmAvgWidth
;
197 NewTextMetricExW2A(NEWTEXTMETRICEXA
*tma
, NEWTEXTMETRICEXW
*tmw
)
199 NewTextMetricW2A(&tma
->ntmTm
, &tmw
->ntmTm
);
200 tma
->ntmFontSig
= tmw
->ntmFontSig
;
204 IntEnumFontFamilies(HDC Dc
, LPLOGFONTW LogFont
, PVOID EnumProc
, LPARAM lParam
,
209 PFONTFAMILYINFO Info
;
212 ENUMLOGFONTEXA EnumLogFontExA
;
213 NEWTEXTMETRICEXA NewTextMetricExA
;
216 Info
= RtlAllocateHeap(GetProcessHeap(), 0,
217 INITIAL_FAMILY_COUNT
* sizeof(FONTFAMILYINFO
));
225 lfW
.lfCharSet
= DEFAULT_CHARSET
;
226 lfW
.lfPitchAndFamily
= 0;
227 lfW
.lfFaceName
[0] = 0;
231 FontFamilyCount
= NtGdiGetFontFamilyInfo(Dc
, LogFont
, Info
, INITIAL_FAMILY_COUNT
);
232 if (FontFamilyCount
< 0)
234 RtlFreeHeap(GetProcessHeap(), 0, Info
);
237 if (INITIAL_FAMILY_COUNT
< FontFamilyCount
)
239 FontFamilySize
= FontFamilyCount
;
240 RtlFreeHeap(GetProcessHeap(), 0, Info
);
241 Info
= RtlAllocateHeap(GetProcessHeap(), 0,
242 FontFamilyCount
* sizeof(FONTFAMILYINFO
));
247 FontFamilyCount
= NtGdiGetFontFamilyInfo(Dc
, LogFont
, Info
, FontFamilySize
);
248 if (FontFamilyCount
< 0 || FontFamilySize
< FontFamilyCount
)
250 RtlFreeHeap(GetProcessHeap(), 0, Info
);
255 for (i
= 0; i
< FontFamilyCount
; i
++)
259 Ret
= ((FONTENUMPROCW
) EnumProc
)(
260 (VOID
*)&Info
[i
].EnumLogFontEx
,
261 (VOID
*)&Info
[i
].NewTextMetricEx
,
262 Info
[i
].FontType
, lParam
);
266 // Could use EnumLogFontExW2A here?
267 LogFontW2A(&EnumLogFontExA
.elfLogFont
, &Info
[i
].EnumLogFontEx
.elfLogFont
);
268 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfFullName
, -1,
269 (LPSTR
)EnumLogFontExA
.elfFullName
, LF_FULLFACESIZE
, NULL
, NULL
);
270 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfStyle
, -1,
271 (LPSTR
)EnumLogFontExA
.elfStyle
, LF_FACESIZE
, NULL
, NULL
);
272 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfScript
, -1,
273 (LPSTR
)EnumLogFontExA
.elfScript
, LF_FACESIZE
, NULL
, NULL
);
274 NewTextMetricExW2A(&NewTextMetricExA
,
275 &Info
[i
].NewTextMetricEx
);
276 Ret
= ((FONTENUMPROCA
) EnumProc
)(
277 (VOID
*)&EnumLogFontExA
,
278 (VOID
*)&NewTextMetricExA
,
279 Info
[i
].FontType
, lParam
);
283 RtlFreeHeap(GetProcessHeap(), 0, Info
);
292 EnumFontFamiliesExW(HDC hdc
, LPLOGFONTW lpLogfont
, FONTENUMPROCW lpEnumFontFamExProc
,
293 LPARAM lParam
, DWORD dwFlags
)
295 return IntEnumFontFamilies(hdc
, lpLogfont
, lpEnumFontFamExProc
, lParam
, TRUE
);
303 EnumFontFamiliesW(HDC hdc
, LPCWSTR lpszFamily
, FONTENUMPROCW lpEnumFontFamProc
,
308 ZeroMemory(&LogFont
, sizeof(LOGFONTW
));
309 LogFont
.lfCharSet
= DEFAULT_CHARSET
;
310 if (NULL
!= lpszFamily
)
312 if (!*lpszFamily
) return 1;
313 lstrcpynW(LogFont
.lfFaceName
, lpszFamily
, LF_FACESIZE
);
316 return IntEnumFontFamilies(hdc
, &LogFont
, lpEnumFontFamProc
, lParam
, TRUE
);
324 EnumFontFamiliesExA (HDC hdc
, LPLOGFONTA lpLogfont
, FONTENUMPROCA lpEnumFontFamExProc
,
325 LPARAM lParam
, DWORD dwFlags
)
327 LOGFONTW LogFontW
, *pLogFontW
;
331 LogFontA2W(&LogFontW
,lpLogfont
);
332 pLogFontW
= &LogFontW
;
334 else pLogFontW
= NULL
;
336 /* no need to convert LogFontW back to lpLogFont b/c it's an [in] parameter only */
337 return IntEnumFontFamilies(hdc
, pLogFontW
, lpEnumFontFamExProc
, lParam
, FALSE
);
345 EnumFontFamiliesA(HDC hdc
, LPCSTR lpszFamily
, FONTENUMPROCA lpEnumFontFamProc
,
350 ZeroMemory(&LogFont
, sizeof(LOGFONTW
));
351 LogFont
.lfCharSet
= DEFAULT_CHARSET
;
352 if (NULL
!= lpszFamily
)
354 if (!*lpszFamily
) return 1;
355 MultiByteToWideChar(CP_THREAD_ACP
, 0, lpszFamily
, -1, LogFont
.lfFaceName
, LF_FACESIZE
);
358 return IntEnumFontFamilies(hdc
, &LogFont
, lpEnumFontFamProc
, lParam
, FALSE
);
367 GetCharacterPlacementA(
372 GCP_RESULTSA
*lpResults
,
377 GCP_RESULTSW resultsW
;
381 if ( !lpString
|| uCount
<= 0 || (nMaxExtent
< 0 && nMaxExtent
!= -1 ) )
383 SetLastError(ERROR_INVALID_PARAMETER
);
386 /* TRACE("%s, %d, %d, 0x%08x\n",
387 debugstr_an(lpString, uCount), uCount, nMaxExtent, dwFlags);
389 /* both structs are equal in size */
390 memcpy(&resultsW
, lpResults
, sizeof(resultsW
));
392 lpStringW
= FONT_mbtowc(hdc
, lpString
, uCount
, &uCountW
, &font_cp
);
393 if (lpStringW
== NULL
)
397 if(lpResults
->lpOutString
)
399 resultsW
.lpOutString
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*uCountW
);
400 if (resultsW
.lpOutString
== NULL
)
402 HeapFree(GetProcessHeap(), 0, lpStringW
);
407 ret
= GetCharacterPlacementW(hdc
, lpStringW
, uCountW
, nMaxExtent
, &resultsW
, dwFlags
);
409 lpResults
->nGlyphs
= resultsW
.nGlyphs
;
410 lpResults
->nMaxFit
= resultsW
.nMaxFit
;
412 if(lpResults
->lpOutString
)
414 WideCharToMultiByte(font_cp
, 0, resultsW
.lpOutString
, uCountW
,
415 lpResults
->lpOutString
, uCount
, NULL
, NULL
);
418 HeapFree(GetProcessHeap(), 0, lpStringW
);
419 HeapFree(GetProcessHeap(), 0, resultsW
.lpOutString
);
430 GetCharacterPlacementW(
435 GCP_RESULTSW
*lpResults
,
442 DPRINT("GetCharacterPlacementW\n");
444 if(dwFlags
&(~GCP_REORDER
)) DPRINT("flags 0x%08lx ignored\n", dwFlags
);
445 if(lpResults
->lpClass
) DPRINT("classes not implemented\n");
446 if (lpResults
->lpCaretPos
&& (dwFlags
& GCP_REORDER
))
447 DPRINT("Caret positions for complex scripts not implemented\n");
450 if(nSet
> lpResults
->nGlyphs
)
451 nSet
= lpResults
->nGlyphs
;
453 /* return number of initialized fields */
454 lpResults
->nGlyphs
= nSet
;
456 /*if((dwFlags&GCP_REORDER)==0 || !BidiAvail)
458 /* Treat the case where no special handling was requested in a fastpath way */
459 /* copy will do if the GCP_REORDER flag is not set */
460 if(lpResults
->lpOutString
)
461 lstrcpynW( lpResults
->lpOutString
, lpString
, nSet
);
463 if(lpResults
->lpOrder
)
465 for(i
= 0; i
< nSet
; i
++)
466 lpResults
->lpOrder
[i
] = i
;
470 BIDI_Reorder( lpString, uCount, dwFlags, WINE_GCPW_FORCE_LTR, lpResults->lpOutString,
471 nSet, lpResults->lpOrder );
474 /* FIXME: Will use the placement chars */
478 for (i
= 0; i
< nSet
; i
++)
480 if (GetCharWidth32W(hdc
, lpString
[i
], lpString
[i
], &c
))
481 lpResults
->lpDx
[i
]= c
;
485 if (lpResults
->lpCaretPos
&& !(dwFlags
& GCP_REORDER
))
489 lpResults
->lpCaretPos
[0] = 0;
490 for (i
= 1; i
< nSet
; i
++)
491 if (GetTextExtentPoint32W(hdc
, &(lpString
[i
- 1]), 1, &size
))
492 lpResults
->lpCaretPos
[i
] = (pos
+= size
.cx
);
495 if (lpResults
->lpGlyphs
)
496 NtGdiGetGlyphIndicesW(hdc
, lpString
, nSet
, lpResults
->lpGlyphs
, 0);
498 if (GetTextExtentPoint32W(hdc
, lpString
, uCount
, &size
))
499 ret
= MAKELONG(size
.cx
, size
.cy
);
506 NewGetCharacterPlacementW(
511 GCP_RESULTSW
*lpResults
,
518 if ( !lpString
|| uCount
<= 0 || (nMaxExtent
< 0 && nMaxExtent
!= -1 ) )
520 SetLastError(ERROR_INVALID_PARAMETER
);
526 if ( GetTextExtentPointW(hdc
, lpString
, uCount
, &Size
) )
528 return MAKELONG(Size
.cx
, Size
.cy
);
534 if ( nSet
> lpResults
->nGlyphs
)
535 nSet
= lpResults
->nGlyphs
;
537 return NtGdiGetCharacterPlacementW( hdc
,
551 GetCharABCWidthsFloatW(HDC hdc
,
556 DPRINT("GetCharABCWidthsFloatW\n");
557 if ((!abcF
) || (FirstChar
> LastChar
))
559 SetLastError(ERROR_INVALID_PARAMETER
);
562 return NtGdiGetCharABCWidthsW( hdc
,
564 (ULONG
)(LastChar
- FirstChar
+ 1),
576 GetCharWidthFloatW(HDC hdc
,
581 DPRINT("GetCharWidthsFloatW\n");
582 if ((!pxBuffer
) || (iFirstChar
> iLastChar
))
584 SetLastError(ERROR_INVALID_PARAMETER
);
587 return NtGdiGetCharWidthW( hdc
,
589 (ULONG
)(iLastChar
- iFirstChar
+ 1),
601 GetCharWidthW(HDC hdc
,
606 DPRINT("GetCharWidthsW\n");
607 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
609 SetLastError(ERROR_INVALID_PARAMETER
);
612 return NtGdiGetCharWidthW( hdc
,
614 (ULONG
)(iLastChar
- iFirstChar
+ 1),
626 GetCharWidth32W(HDC hdc
,
631 DPRINT("GetCharWidths32W\n");
632 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
634 SetLastError(ERROR_INVALID_PARAMETER
);
637 return NtGdiGetCharWidthW( hdc
,
639 (ULONG
)(iLastChar
- iFirstChar
+ 1),
641 GCW_NOFLOAT
|GCW_WIN32
,
652 GetCharABCWidthsW(HDC hdc
,
657 DPRINT("GetCharABCWidthsW\n");
658 if ((!lpabc
) || (FirstChar
> LastChar
))
660 SetLastError(ERROR_INVALID_PARAMETER
);
663 return NtGdiGetCharABCWidthsW( hdc
,
665 (ULONG
)(LastChar
- FirstChar
+ 1),
688 DPRINT("GetCharWidthsA\n");
690 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
694 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
697 HeapFree(GetProcessHeap(), 0, str
);
701 ret
= NtGdiGetCharWidthW( hdc
,
708 HeapFree(GetProcessHeap(), 0, str
);
709 HeapFree(GetProcessHeap(), 0, wstr
);
731 DPRINT("GetCharWidths32A\n");
733 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
737 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
740 HeapFree(GetProcessHeap(), 0, str
);
744 ret
= NtGdiGetCharWidthW( hdc
,
748 GCW_NOFLOAT
|GCW_WIN32
,
751 HeapFree(GetProcessHeap(), 0, str
);
752 HeapFree(GetProcessHeap(), 0, wstr
);
774 DPRINT("GetCharWidthsFloatA\n");
776 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
780 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
783 HeapFree(GetProcessHeap(), 0, str
);
786 ret
= NtGdiGetCharWidthW( hdc
, wstr
[0], (ULONG
) count
, (PWCHAR
) wstr
, 0, (PVOID
) pxBuffer
);
788 HeapFree(GetProcessHeap(), 0, str
);
789 HeapFree(GetProcessHeap(), 0, wstr
);
811 DPRINT("GetCharABCWidthsA\n");
813 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
817 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
820 HeapFree(GetProcessHeap(), 0, str
);
824 ret
= NtGdiGetCharABCWidthsW( hdc
,
831 HeapFree(GetProcessHeap(), 0, str
);
832 HeapFree(GetProcessHeap(), 0, wstr
);
842 GetCharABCWidthsFloatA(
854 DPRINT("GetCharABCWidthsFloatA\n");
856 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
860 wstr
= FONT_mbtowc( hdc
, str
, count
+1, &wlen
, NULL
);
863 HeapFree( GetProcessHeap(), 0, str
);
866 ret
= NtGdiGetCharABCWidthsW( hdc
,wstr
[0],(ULONG
)count
, (PWCHAR
)wstr
, 0, (PVOID
)lpABCF
);
868 HeapFree( GetProcessHeap(), 0, str
);
869 HeapFree( GetProcessHeap(), 0, wstr
);
879 GetCharABCWidthsI(HDC hdc
,
885 DPRINT("GetCharABCWidthsI\n");
886 return NtGdiGetCharABCWidthsW( hdc
,
890 GCABCW_NOFLOAT
|GCABCW_INDICES
,
899 GetCharWidthI(HDC hdc
,
906 DPRINT("GetCharWidthsI\n");
907 if (!lpBuffer
|| (!pgi
&& (giFirst
== MAXUSHORT
))) // Cannot be at max.
909 SetLastError(ERROR_INVALID_PARAMETER
);
912 if (!cgi
) return TRUE
;
913 return NtGdiGetCharWidthW( hdc
,
917 GCW_INDICES
|GCW_NOFLOAT
|GCW_WIN32
,
930 DWORD Gcp
= 0, Ret
= 0;
933 Ret
= NtGdiGetTextCharsetInfo(hDc
, NULL
, 0);
934 if ((Ret
== ARABIC_CHARSET
) || (Ret
== HEBREW_CHARSET
))
935 Ret
= (GCP_KASHIDA
|GCP_DIACRITIC
|GCP_LIGATE
|GCP_GLYPHSHAPE
|GCP_REORDER
);
937 Gcp
= GetDCDWord(hDc
, GdiGetFontLanguageInfo
, GCP_ERROR
);
938 if ( Gcp
== GCP_ERROR
)
962 lpstrW
= FONT_mbtowc(hdc
, lpstr
, count
, &countW
, NULL
);
967 Ret
= NtGdiGetGlyphIndicesW(hdc
, lpstrW
, countW
, pgi
, flags
);
968 HeapFree(GetProcessHeap(), 0, lpstrW
);
991 DPRINT("GetGlyphOutlineA uChar %x\n", uChar
);
992 if (!lpgm
|| !lpmat2
) return GDI_ERROR
;
993 if(!(uFormat
& GGO_GLYPH_INDEX
))
997 if(uChar
> 0xff) /* but, 2 bytes character only */
1000 mbchs
[0] = (uChar
& 0xff00) >> 8;
1001 mbchs
[1] = (uChar
& 0xff);
1006 mbchs
[0] = (uChar
& 0xff);
1008 p
= FONT_mbtowc(hdc
, mbchs
, len
, NULL
, NULL
);
1013 ret
= NtGdiGetGlyphOutline(hdc
, c
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1014 HeapFree(GetProcessHeap(), 0, p
);
1028 LPGLYPHMETRICS lpgm
,
1034 DPRINT("GetGlyphOutlineW uChar %x\n", uChar
);
1035 if (!lpgm
|| !lpmat2
) return GDI_ERROR
;
1036 if (!lpvBuffer
) cbBuffer
= 0;
1037 return NtGdiGetGlyphOutline ( hdc
, uChar
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1056 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1065 GetOutlineTextMetricsA(
1068 LPOUTLINETEXTMETRICA lpOTM
1071 char buf
[512], *ptr
;
1073 OUTLINETEXTMETRICW
*lpOTMW
= (OUTLINETEXTMETRICW
*)buf
;
1074 OUTLINETEXTMETRICA
*output
= lpOTM
;
1077 if((ret
= GetOutlineTextMetricsW(hdc
, 0, NULL
)) == 0)
1079 if(ret
> sizeof(buf
))
1081 lpOTMW
= HeapAlloc(GetProcessHeap(), 0, ret
);
1087 GetOutlineTextMetricsW(hdc
, ret
, lpOTMW
);
1089 needed
= sizeof(OUTLINETEXTMETRICA
);
1090 if(lpOTMW
->otmpFamilyName
)
1091 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1092 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1093 NULL
, 0, NULL
, NULL
);
1094 if(lpOTMW
->otmpFaceName
)
1095 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1096 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1097 NULL
, 0, NULL
, NULL
);
1098 if(lpOTMW
->otmpStyleName
)
1099 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1100 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1101 NULL
, 0, NULL
, NULL
);
1102 if(lpOTMW
->otmpFullName
)
1103 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1104 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1105 NULL
, 0, NULL
, NULL
);
1113 DPRINT("needed = %u\n", needed
);
1116 /* Since the supplied buffer isn't big enough, we'll alloc one
1117 that is and memcpy the first cbData bytes into the lpOTM at
1119 output
= HeapAlloc(GetProcessHeap(), 0, needed
);
1126 ret
= output
->otmSize
= min(needed
, cbData
);
1127 FONT_TextMetricWToA( &lpOTMW
->otmTextMetrics
, &output
->otmTextMetrics
);
1128 output
->otmFiller
= 0;
1129 output
->otmPanoseNumber
= lpOTMW
->otmPanoseNumber
;
1130 output
->otmfsSelection
= lpOTMW
->otmfsSelection
;
1131 output
->otmfsType
= lpOTMW
->otmfsType
;
1132 output
->otmsCharSlopeRise
= lpOTMW
->otmsCharSlopeRise
;
1133 output
->otmsCharSlopeRun
= lpOTMW
->otmsCharSlopeRun
;
1134 output
->otmItalicAngle
= lpOTMW
->otmItalicAngle
;
1135 output
->otmEMSquare
= lpOTMW
->otmEMSquare
;
1136 output
->otmAscent
= lpOTMW
->otmAscent
;
1137 output
->otmDescent
= lpOTMW
->otmDescent
;
1138 output
->otmLineGap
= lpOTMW
->otmLineGap
;
1139 output
->otmsCapEmHeight
= lpOTMW
->otmsCapEmHeight
;
1140 output
->otmsXHeight
= lpOTMW
->otmsXHeight
;
1141 output
->otmrcFontBox
= lpOTMW
->otmrcFontBox
;
1142 output
->otmMacAscent
= lpOTMW
->otmMacAscent
;
1143 output
->otmMacDescent
= lpOTMW
->otmMacDescent
;
1144 output
->otmMacLineGap
= lpOTMW
->otmMacLineGap
;
1145 output
->otmusMinimumPPEM
= lpOTMW
->otmusMinimumPPEM
;
1146 output
->otmptSubscriptSize
= lpOTMW
->otmptSubscriptSize
;
1147 output
->otmptSubscriptOffset
= lpOTMW
->otmptSubscriptOffset
;
1148 output
->otmptSuperscriptSize
= lpOTMW
->otmptSuperscriptSize
;
1149 output
->otmptSuperscriptOffset
= lpOTMW
->otmptSuperscriptOffset
;
1150 output
->otmsStrikeoutSize
= lpOTMW
->otmsStrikeoutSize
;
1151 output
->otmsStrikeoutPosition
= lpOTMW
->otmsStrikeoutPosition
;
1152 output
->otmsUnderscoreSize
= lpOTMW
->otmsUnderscoreSize
;
1153 output
->otmsUnderscorePosition
= lpOTMW
->otmsUnderscorePosition
;
1156 ptr
= (char*)(output
+ 1);
1157 left
= needed
- sizeof(*output
);
1159 if(lpOTMW
->otmpFamilyName
)
1161 output
->otmpFamilyName
= (LPSTR
)(ptr
- (char*)output
);
1162 len
= WideCharToMultiByte(CP_ACP
, 0,
1163 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1164 ptr
, left
, NULL
, NULL
);
1169 output
->otmpFamilyName
= 0;
1171 if(lpOTMW
->otmpFaceName
)
1173 output
->otmpFaceName
= (LPSTR
)(ptr
- (char*)output
);
1174 len
= WideCharToMultiByte(CP_ACP
, 0,
1175 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1176 ptr
, left
, NULL
, NULL
);
1181 output
->otmpFaceName
= 0;
1183 if(lpOTMW
->otmpStyleName
)
1185 output
->otmpStyleName
= (LPSTR
)(ptr
- (char*)output
);
1186 len
= WideCharToMultiByte(CP_ACP
, 0,
1187 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1188 ptr
, left
, NULL
, NULL
);
1193 output
->otmpStyleName
= 0;
1195 if(lpOTMW
->otmpFullName
)
1197 output
->otmpFullName
= (LPSTR
)(ptr
- (char*)output
);
1198 len
= WideCharToMultiByte(CP_ACP
, 0,
1199 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1200 ptr
, left
, NULL
, NULL
);
1204 output
->otmpFullName
= 0;
1210 memcpy(lpOTM
, output
, cbData
);
1211 HeapFree(GetProcessHeap(), 0, output
);
1213 /* check if the string offsets really fit into the provided size */
1214 /* FIXME: should we check string length as well? */
1215 if ((UINT_PTR
)lpOTM
->otmpFamilyName
>= lpOTM
->otmSize
)
1216 lpOTM
->otmpFamilyName
= 0; /* doesn't fit */
1218 if ((UINT_PTR
)lpOTM
->otmpFaceName
>= lpOTM
->otmSize
)
1219 lpOTM
->otmpFaceName
= 0; /* doesn't fit */
1221 if ((UINT_PTR
)lpOTM
->otmpStyleName
>= lpOTM
->otmSize
)
1222 lpOTM
->otmpStyleName
= 0; /* doesn't fit */
1224 if ((UINT_PTR
)lpOTM
->otmpFullName
>= lpOTM
->otmSize
)
1225 lpOTM
->otmpFullName
= 0; /* doesn't fit */
1229 if(lpOTMW
!= (OUTLINETEXTMETRICW
*)buf
)
1230 HeapFree(GetProcessHeap(), 0, lpOTMW
);
1235 /* Performs a device to world transformation on the specified size (which
1236 * is in integer format).
1238 static inline INT
INTERNAL_YDSTOWS(XFORM
*xForm
, INT height
)
1242 /* Perform operation with floating point */
1243 floatHeight
= (double)height
* xForm
->eM22
;
1244 /* Round to integers */
1245 return GDI_ROUND(floatHeight
);
1248 /* scale width and height but don't mirror them */
1249 static inline INT
width_to_LP( XFORM
*xForm
, INT width
)
1251 return GDI_ROUND( (double)width
* fabs( xForm
->eM11
));
1254 static inline INT
height_to_LP( XFORM
*xForm
, INT height
)
1256 return GDI_ROUND( (double)height
* fabs( xForm
->eM22
));
1264 GetOutlineTextMetricsW(
1267 LPOUTLINETEXTMETRICW lpOTM
1270 TMDIFF Tmd
; // Should not be zero.
1271 UINT Size
, AvailableSize
= 0, StringSize
;
1273 OUTLINETEXTMETRICW
* LocalOTM
;
1277 /* Get the structure */
1278 Size
= NtGdiGetOutlineTextMetricsInternalW(hdc
, 0, NULL
, &Tmd
);
1281 if (!lpOTM
|| (cbData
< sizeof(*lpOTM
)))
1284 LocalOTM
= HeapAlloc(GetProcessHeap(), 0, Size
);
1285 LocalOTM
->otmSize
= Size
;
1286 Size
= NtGdiGetOutlineTextMetricsInternalW(hdc
, Size
, LocalOTM
, &Tmd
);
1289 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1293 if (!NtGdiGetTransform(hdc
, GdiDeviceSpaceToWorldSpace
, &DevToWorld
))
1295 DPRINT1("NtGdiGetTransform failed!\n");
1296 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1297 SetLastError(ERROR_INVALID_HANDLE
);
1301 /* Fill in DC specific data */
1302 LocalOTM
->otmTextMetrics
.tmDigitizedAspectX
= GetDeviceCaps(hdc
, LOGPIXELSX
);
1303 LocalOTM
->otmTextMetrics
.tmDigitizedAspectY
= GetDeviceCaps(hdc
, LOGPIXELSY
);
1304 LocalOTM
->otmTextMetrics
.tmHeight
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmHeight
);
1305 LocalOTM
->otmTextMetrics
.tmAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmAscent
);
1306 LocalOTM
->otmTextMetrics
.tmDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmDescent
);
1307 LocalOTM
->otmTextMetrics
.tmInternalLeading
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmInternalLeading
);
1308 LocalOTM
->otmTextMetrics
.tmExternalLeading
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmExternalLeading
);
1309 LocalOTM
->otmTextMetrics
.tmAveCharWidth
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmAveCharWidth
);
1310 LocalOTM
->otmTextMetrics
.tmMaxCharWidth
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmMaxCharWidth
);
1311 LocalOTM
->otmTextMetrics
.tmOverhang
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmOverhang
);
1312 LocalOTM
->otmAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmAscent
);
1313 LocalOTM
->otmDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmDescent
);
1314 LocalOTM
->otmLineGap
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmLineGap
));
1315 LocalOTM
->otmsCapEmHeight
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsCapEmHeight
));
1316 LocalOTM
->otmsXHeight
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsXHeight
));
1317 LocalOTM
->otmrcFontBox
.top
= height_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.top
);
1318 LocalOTM
->otmrcFontBox
.bottom
= height_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.bottom
);
1319 LocalOTM
->otmrcFontBox
.left
= width_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.left
);
1320 LocalOTM
->otmrcFontBox
.right
= width_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.right
);
1321 LocalOTM
->otmMacAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmMacAscent
);
1322 LocalOTM
->otmMacDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmMacDescent
);
1323 LocalOTM
->otmMacLineGap
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmMacLineGap
));
1324 LocalOTM
->otmptSubscriptSize
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptSize
.x
);
1325 LocalOTM
->otmptSubscriptSize
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptSize
.y
);
1326 LocalOTM
->otmptSubscriptOffset
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptOffset
.x
);
1327 LocalOTM
->otmptSubscriptOffset
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptOffset
.y
);
1328 LocalOTM
->otmptSuperscriptSize
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptSize
.x
);
1329 LocalOTM
->otmptSuperscriptSize
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptSize
.y
);
1330 LocalOTM
->otmptSuperscriptOffset
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptOffset
.x
);
1331 LocalOTM
->otmptSuperscriptOffset
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptOffset
.y
);
1332 LocalOTM
->otmsStrikeoutSize
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsStrikeoutSize
));
1333 LocalOTM
->otmsStrikeoutPosition
= height_to_LP( &DevToWorld
, LocalOTM
->otmsStrikeoutPosition
);
1334 LocalOTM
->otmsUnderscoreSize
= height_to_LP( &DevToWorld
, LocalOTM
->otmsUnderscoreSize
);
1335 LocalOTM
->otmsUnderscorePosition
= height_to_LP( &DevToWorld
, LocalOTM
->otmsUnderscorePosition
);
1337 /* Copy what we can */
1338 CopyMemory(lpOTM
, LocalOTM
, min(Size
, cbData
));
1340 lpOTM
->otmpFamilyName
= NULL
;
1341 lpOTM
->otmpFaceName
= NULL
;
1342 lpOTM
->otmpStyleName
= NULL
;
1343 lpOTM
->otmpFullName
= NULL
;
1345 Size
= sizeof(*lpOTM
);
1346 AvailableSize
= cbData
- Size
;
1347 Ptr
= (BYTE
*)lpOTM
+ sizeof(*lpOTM
);
1349 /* Fix string values up */
1350 if (LocalOTM
->otmpFamilyName
)
1352 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFamilyName
);
1353 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1354 if (AvailableSize
>= StringSize
)
1356 CopyMemory(Ptr
, Str
, StringSize
);
1357 lpOTM
->otmpFamilyName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1359 AvailableSize
-= StringSize
;
1364 if (LocalOTM
->otmpFaceName
)
1366 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFaceName
);
1367 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1368 if (AvailableSize
>= StringSize
)
1370 CopyMemory(Ptr
, Str
, StringSize
);
1371 lpOTM
->otmpFaceName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1373 AvailableSize
-= StringSize
;
1378 if (LocalOTM
->otmpStyleName
)
1380 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpStyleName
);
1381 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1382 if (AvailableSize
>= StringSize
)
1384 CopyMemory(Ptr
, Str
, StringSize
);
1385 lpOTM
->otmpStyleName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1387 AvailableSize
-= StringSize
;
1392 if (LocalOTM
->otmpFullName
)
1394 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFullName
);
1395 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1396 if (AvailableSize
>= StringSize
)
1398 CopyMemory(Ptr
, Str
, StringSize
);
1399 lpOTM
->otmpFullName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1401 AvailableSize
-= StringSize
;
1406 lpOTM
->otmSize
= Size
;
1408 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1418 GetKerningPairsW(HDC hdc
,
1420 LPKERNINGPAIR pkpDst
)
1422 if ((cPairs
!= 0) || (pkpDst
== 0))
1424 return NtGdiGetKerningPairs(hdc
,cPairs
,pkpDst
);
1428 SetLastError(ERROR_INVALID_PARAMETER
);
1438 GetKerningPairsA( HDC hDC
,
1440 LPKERNINGPAIR kern_pairA
)
1445 DWORD i
, total_kern_pairs
, kern_pairs_copied
= 0;
1446 KERNINGPAIR
*kern_pairW
;
1448 if (!cPairs
&& kern_pairA
)
1450 SetLastError(ERROR_INVALID_PARAMETER
);
1454 charset
= GetTextCharset(hDC
);
1455 if (!TranslateCharsetInfo(ULongToPtr(charset
), &csi
, TCI_SRCCHARSET
))
1457 DPRINT1("Can't find codepage for charset %d\n", charset
);
1460 /* GetCPInfo() will fail on CP_SYMBOL, and WideCharToMultiByte is supposed
1461 * to fail on an invalid character for CP_SYMBOL.
1463 cpi
.DefaultChar
[0] = 0;
1464 if (csi
.ciACP
!= CP_SYMBOL
&& !GetCPInfo(csi
.ciACP
, &cpi
))
1466 DPRINT1("Can't find codepage %u info\n", csi
.ciACP
);
1469 DPRINT("charset %d => codepage %u\n", charset
, csi
.ciACP
);
1471 total_kern_pairs
= NtGdiGetKerningPairs(hDC
, 0, NULL
);
1472 if (!total_kern_pairs
) return 0;
1474 if (!cPairs
&& !kern_pairA
) return total_kern_pairs
;
1476 kern_pairW
= HeapAlloc(GetProcessHeap(), 0, total_kern_pairs
* sizeof(*kern_pairW
));
1477 if (kern_pairW
== NULL
)
1481 GetKerningPairsW(hDC
, total_kern_pairs
, kern_pairW
);
1483 for (i
= 0; i
< total_kern_pairs
; i
++)
1487 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wFirst
, 1, &first
, 1, NULL
, NULL
))
1490 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wSecond
, 1, &second
, 1, NULL
, NULL
))
1493 if (first
== cpi
.DefaultChar
[0] || second
== cpi
.DefaultChar
[0])
1498 if (kern_pairs_copied
>= cPairs
) break;
1500 kern_pairA
->wFirst
= (BYTE
)first
;
1501 kern_pairA
->wSecond
= (BYTE
)second
;
1502 kern_pairA
->iKernAmount
= kern_pairW
[i
].iKernAmount
;
1505 kern_pairs_copied
++;
1508 HeapFree(GetProcessHeap(), 0, kern_pairW
);
1510 return kern_pairs_copied
;
1520 CreateFontIndirectExA(const ENUMLOGFONTEXDVA
*elfexd
)
1524 ENUMLOGFONTEXDVW Logfont
;
1526 EnumLogFontExW2A( (LPENUMLOGFONTEXA
) elfexd
,
1527 &Logfont
.elfEnumLogfontEx
);
1529 RtlCopyMemory( &Logfont
.elfDesignVector
,
1530 (PVOID
) &elfexd
->elfDesignVector
,
1531 sizeof(DESIGNVECTOR
));
1533 return NtGdiHfontCreate( &Logfont
, 0, 0, 0, NULL
);
1544 CreateFontIndirectExW(const ENUMLOGFONTEXDVW
*elfexd
)
1546 /* Msdn: Note, this function ignores the elfDesignVector member in
1551 return NtGdiHfontCreate((PENUMLOGFONTEXDVW
) elfexd
, 0, 0, 0, NULL
);
1562 CreateFontIndirectA(
1563 CONST LOGFONTA
*lplf
1570 LogFontA2W(&tlf
, lplf
);
1571 return CreateFontIndirectW(&tlf
);
1582 CreateFontIndirectW(
1583 CONST LOGFONTW
*lplf
1588 ENUMLOGFONTEXDVW Logfont
;
1590 RtlCopyMemory( &Logfont
.elfEnumLogfontEx
.elfLogFont
, lplf
, sizeof(LOGFONTW
));
1591 // Need something other than just cleaning memory here.
1592 // Guess? Use caller data to determine the rest.
1593 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfFullName
,
1594 sizeof(Logfont
.elfEnumLogfontEx
.elfFullName
));
1595 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfStyle
,
1596 sizeof(Logfont
.elfEnumLogfontEx
.elfStyle
));
1597 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfScript
,
1598 sizeof(Logfont
.elfEnumLogfontEx
.elfScript
));
1600 Logfont
.elfDesignVector
.dvNumAxes
= 0; // No more than MM_MAX_NUMAXES
1602 RtlZeroMemory( &Logfont
.elfDesignVector
, sizeof(DESIGNVECTOR
));
1604 return CreateFontIndirectExW(&Logfont
);
1625 DWORD fdwOutputPrecision
,
1626 DWORD fdwClipPrecision
,
1628 DWORD fdwPitchAndFamily
,
1632 ANSI_STRING StringA
;
1633 UNICODE_STRING StringU
;
1636 RtlInitAnsiString(&StringA
, (LPSTR
)lpszFace
);
1637 RtlAnsiStringToUnicodeString(&StringU
, &StringA
, TRUE
);
1639 ret
= CreateFontW(nHeight
,
1654 RtlFreeUnicodeString(&StringU
);
1675 DWORD fdwOutputPrecision
,
1676 DWORD fdwClipPrecision
,
1678 DWORD fdwPitchAndFamily
,
1684 logfont
.lfHeight
= nHeight
;
1685 logfont
.lfWidth
= nWidth
;
1686 logfont
.lfEscapement
= nEscapement
;
1687 logfont
.lfOrientation
= nOrientation
;
1688 logfont
.lfWeight
= nWeight
;
1689 logfont
.lfItalic
= (BYTE
)fnItalic
;
1690 logfont
.lfUnderline
= (BYTE
)fdwUnderline
;
1691 logfont
.lfStrikeOut
= (BYTE
)fdwStrikeOut
;
1692 logfont
.lfCharSet
= (BYTE
)fdwCharSet
;
1693 logfont
.lfOutPrecision
= (BYTE
)fdwOutputPrecision
;
1694 logfont
.lfClipPrecision
= (BYTE
)fdwClipPrecision
;
1695 logfont
.lfQuality
= (BYTE
)fdwQuality
;
1696 logfont
.lfPitchAndFamily
= (BYTE
)fdwPitchAndFamily
;
1698 if (NULL
!= lpszFace
)
1700 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
1701 wcsncpy((wchar_t *)logfont
.lfFaceName
, lpszFace
, Size
- 1);
1702 /* Be 101% sure to have '\0' at end of string */
1703 logfont
.lfFaceName
[Size
- 1] = '\0';
1707 logfont
.lfFaceName
[0] = L
'\0';
1710 return CreateFontIndirectW(&logfont
);
1719 CreateScalableFontResourceA(
1722 LPCSTR lpszFontFile
,
1723 LPCSTR lpszCurrentPath
1735 AddFontResourceExW ( LPCWSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1737 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1739 SetLastError( ERROR_INVALID_PARAMETER
);
1743 return GdiAddFontResourceW(lpszFilename
, fl
,0);
1752 AddFontResourceExA ( LPCSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1758 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1760 SetLastError( ERROR_INVALID_PARAMETER
);
1764 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1765 if ( !NT_SUCCESS (Status
) )
1767 SetLastError (RtlNtStatusToDosError(Status
));
1771 rc
= GdiAddFontResourceW ( FilenameW
, fl
, 0 );
1772 HEAP_free ( FilenameW
);
1782 AddFontResourceA ( LPCSTR lpszFilename
)
1788 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1789 if ( !NT_SUCCESS (Status
) )
1791 SetLastError (RtlNtStatusToDosError(Status
));
1795 rc
= GdiAddFontResourceW ( FilenameW
, 0, 0);
1797 HEAP_free ( FilenameW
);
1808 AddFontResourceW ( LPCWSTR lpszFilename
)
1810 return GdiAddFontResourceW ( lpszFilename
, 0, 0 );
1819 RemoveFontResourceW(LPCWSTR lpFileName
)
1821 return RemoveFontResourceExW(lpFileName
,0,0);
1830 RemoveFontResourceA(LPCSTR lpFileName
)
1832 return RemoveFontResourceExA(lpFileName
,0,0);
1840 RemoveFontResourceExA(LPCSTR lpFileName
,
1848 /* FIXME the flags */
1850 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1852 Status
= HEAP_strdupA2W ( &lpFileNameW
, lpFileName
);
1853 if (!NT_SUCCESS (Status
))
1854 SetLastError (RtlNtStatusToDosError(Status
));
1858 HEAP_free ( lpFileNameW
);
1869 RemoveFontResourceExW(LPCWSTR lpFileName
,
1873 /* FIXME the flags */
1875 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1880 /***********************************************************************
1881 * GdiGetCharDimensions
1883 * Gets the average width of the characters in the English alphabet.
1886 * hdc [I] Handle to the device context to measure on.
1887 * lptm [O] Pointer to memory to store the text metrics into.
1888 * height [O] On exit, the maximum height of characters in the English alphabet.
1891 * The average width of characters in the English alphabet.
1894 * This function is used by the dialog manager to get the size of a dialog
1895 * unit. It should also be used by other pieces of code that need to know
1896 * the size of a dialog unit in logical units without having access to the
1897 * window handle of the dialog.
1898 * Windows caches the font metrics from this function, but we don't and
1899 * there doesn't appear to be an immediate advantage to do so.
1902 * GetTextExtentPointW, GetTextMetricsW, MapDialogRect.
1904 * Despite most of MSDN insisting that the horizontal base unit is
1905 * tmAveCharWidth it isn't. Knowledge base article Q145994
1906 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
1907 * says that we should take the average of the 52 English upper and lower
1915 GdiGetCharDimensions(HDC hdc
, LPTEXTMETRICW lptm
, LONG
*height
)
1919 static const WCHAR alphabet
[] =
1921 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
1922 'r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H',
1923 'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',0
1926 if(!GetTextMetricsW(hdc
, &tm
)) return 0;
1928 if(!GetTextExtentPointW(hdc
, alphabet
, 52, &sz
)) return 0;
1930 if (lptm
) *lptm
= tm
;
1931 if (height
) *height
= tm
.tmHeight
;
1933 return (sz
.cx
/ 26 + 1) / 2;
1936 /*************************************************************************
1937 * TranslateCharsetInfo [GDI32.@]
1939 * Fills a CHARSETINFO structure for a character set, code page, or
1940 * font. This allows making the correspondance between different labelings
1941 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1942 * of the same encoding.
1944 * Only one codepage will be set in lpCs->fs. If TCI_SRCFONTSIG is used,
1945 * only one codepage should be set in *lpSrc.
1948 * TRUE on success, FALSE on failure.
1956 TranslateCharsetInfo(
1957 LPDWORD lpSrc
, /* [in]
1958 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1959 if flags == TCI_SRCCHARSET: a character set value
1960 if flags == TCI_SRCCODEPAGE: a code page value
1962 LPCHARSETINFO lpCs
, /* [out] structure to receive charset information */
1963 DWORD flags
/* [in] determines interpretation of lpSrc */)
1968 case TCI_SRCFONTSIG
:
1969 while (index
< MAXTCIINDEX
&& !(*lpSrc
>>index
& 0x0001)) index
++;
1971 case TCI_SRCCODEPAGE
:
1972 while (index
< MAXTCIINDEX
&& PtrToUlong(lpSrc
) != FONT_tci
[index
].ciACP
) index
++;
1974 case TCI_SRCCHARSET
:
1975 while (index
< MAXTCIINDEX
&& PtrToUlong(lpSrc
) != FONT_tci
[index
].ciCharset
) index
++;
1979 LCID lCid
= (LCID
)PtrToUlong(lpSrc
);
1980 LOCALESIGNATURE LocSig
;
1981 INT Ret
= GetLocaleInfoW(lCid
, LOCALE_FONTSIGNATURE
, (LPWSTR
)&LocSig
, 0);
1982 if ( GetLocaleInfoW(lCid
, LOCALE_FONTSIGNATURE
, (LPWSTR
)&LocSig
, Ret
))
1984 while (index
< MAXTCIINDEX
&& !(LocSig
.lsCsbDefault
[0]>>index
& 0x0001)) index
++;
1989 GdiSetLastError(ERROR_INVALID_PARAMETER
);
1992 if (index
>= MAXTCIINDEX
|| FONT_tci
[index
].ciCharset
== DEFAULT_CHARSET
) return FALSE
;
1993 DPRINT("Index %d Charset %u CodePage %u FontSig %lu\n",
1994 index
,FONT_tci
[index
].ciCharset
,FONT_tci
[index
].ciACP
,FONT_tci
[index
].fs
.fsCsb
[0]);
1995 memcpy(lpCs
, &FONT_tci
[index
], sizeof(CHARSETINFO
));
2010 DWORD Ret
= GDI_ERROR
;
2013 if (GDI_HANDLE_GET_TYPE(hDC
) != GDI_OBJECT_TYPE_DC
)
2015 if (GDI_HANDLE_GET_TYPE(hDC
) == GDI_OBJECT_TYPE_METADC
)
2016 return MFDRV_SetMapperFlags( hDC
, flags
);
2019 PLDC pLDC
= Dc_Attr
->pvLDC
;
2022 SetLastError(ERROR_INVALID_HANDLE
);
2025 if (pLDC
->iType
== LDC_EMFLDC
)
2027 return EMFDRV_SetMapperFlags( hDC
, flags
);
2032 if (!GdiGetHandleUserData((HGDIOBJ
) hDC
, GDI_OBJECT_TYPE_DC
, (PVOID
) &Dc_Attr
)) return GDI_ERROR
;
2034 if (NtCurrentTeb()->GdiTebBatch
.HDC
== hDC
)
2036 if (Dc_Attr
->ulDirty_
& DC_FONTTEXT_DIRTY
)
2039 Dc_Attr
->ulDirty_
&= ~(DC_MODE_DIRTY
|DC_FONTTEXT_DIRTY
);
2044 SetLastError(ERROR_INVALID_PARAMETER
);
2047 Ret
= Dc_Attr
->flFontMapper
;
2048 Dc_Attr
->flFontMapper
= flags
;
2062 FONTENUMPROCW FontFunc
,
2067 return NtGdiEnumFonts ( hDC
, lpFaceName
, FontFunc
, lParam
);
2069 return EnumFontFamiliesW( hDC
, lpFaceName
, FontFunc
, lParam
);
2081 FONTENUMPROCA FontFunc
,
2090 Status
= HEAP_strdupA2W ( &lpFaceNameW
, lpFaceName
);
2091 if (!NT_SUCCESS (Status
))
2092 SetLastError (RtlNtStatusToDosError(Status
));
2095 rc
= NtGdiEnumFonts ( hDC
, lpFaceNameW
, FontFunc
, lParam
);
2097 HEAP_free ( lpFaceNameW
);
2101 return EnumFontFamiliesA( hDC
, lpFaceName
, FontFunc
, lParam
);
2105 #define EfdFontFamilies 3
2109 NewEnumFontFamiliesExW(
2111 LPLOGFONTW lpLogfont
,
2112 FONTENUMPROCW lpEnumFontFamExProcW
,
2116 ULONG_PTR idEnum
, cbDataSize
, cbRetSize
;
2117 PENUMFONTDATAW pEfdw
;
2122 /* Open enumeration handle and find out how much memory we need */
2123 idEnum
= NtGdiEnumFontOpen(hDC
,
2127 (lpLogfont
&& lpLogfont
->lfFaceName
[0])? lpLogfont
->lfFaceName
: NULL
,
2128 lpLogfont
? lpLogfont
->lfCharSet
: DEFAULT_CHARSET
,
2134 if (cbDataSize
== 0)
2136 NtGdiEnumFontClose(idEnum
);
2140 /* Allocate memory */
2141 pBuffer
= HeapAlloc(GetProcessHeap(), 0, cbDataSize
);
2142 if (pBuffer
== NULL
)
2144 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2145 NtGdiEnumFontClose(idEnum
);
2149 /* Do the enumeration */
2150 if (!NtGdiEnumFontChunk(hDC
, idEnum
, cbDataSize
, &cbRetSize
, (PVOID
)pBuffer
))
2152 HeapFree(GetProcessHeap(), 0, pBuffer
);
2153 NtGdiEnumFontClose(idEnum
);
2157 /* Get start and end address */
2158 pEfdw
= (PENUMFONTDATAW
)pBuffer
;
2159 pMax
= pBuffer
+ cbDataSize
;
2161 /* Iterate through the structures */
2162 while ((PBYTE
)pEfdw
< pMax
&& ret
)
2164 PNTMW_INTERNAL pNtmwi
= (PNTMW_INTERNAL
)((ULONG_PTR
)pEfdw
+ pEfdw
->ulNtmwiOffset
);
2166 ret
= lpEnumFontFamExProcW((VOID
*)&pEfdw
->elfexdv
.elfEnumLogfontEx
,
2167 (VOID
*)&pNtmwi
->ntmw
,
2171 pEfdw
= (PENUMFONTDATAW
)((ULONG_PTR
)pEfdw
+ pEfdw
->cbSize
);
2174 /* Release the memory and close handle */
2175 HeapFree(GetProcessHeap(), 0, pBuffer
);
2176 NtGdiEnumFontClose(idEnum
);
2186 GdiAddFontResourceW(
2187 LPCWSTR lpszFilename
,
2192 WCHAR lpszBuffer
[MAX_PATH
];
2193 WCHAR lpszAbsPath
[MAX_PATH
];
2194 UNICODE_STRING NtAbsPath
;
2196 /* FIXME: We don't support multiple files passed in lpszFilename
2197 * as L"abcxxxxx.pfm|abcxxxxx.pfb"
2200 /* Does the file exist in CurrentDirectory or in the Absolute Path passed? */
2201 GetCurrentDirectoryW(MAX_PATH
, lpszBuffer
);
2203 if (!SearchPathW(lpszBuffer
, lpszFilename
, NULL
, MAX_PATH
, lpszAbsPath
, NULL
))
2205 /* Nope. Then let's check Fonts folder */
2206 GetWindowsDirectoryW(lpszBuffer
, MAX_PATH
);
2207 StringCbCatW(lpszBuffer
, sizeof(lpszBuffer
), L
"\\Fonts");
2209 if (!SearchPathW(lpszBuffer
, lpszFilename
, NULL
, MAX_PATH
, lpszAbsPath
, NULL
))
2211 DPRINT1("Font not found. The Buffer is: %ls, the FileName is: %S\n", lpszBuffer
, lpszFilename
);
2216 /* We found the font file so: */
2217 if (!RtlDosPathNameToNtPathName_U(lpszAbsPath
, &NtAbsPath
, NULL
, NULL
))
2219 DPRINT1("Can't convert Path! Path: %ls\n", lpszAbsPath
);
2223 /* The Nt call expects a null-terminator included in cwc param. */
2224 ASSERT(NtAbsPath
.Buffer
[NtAbsPath
.Length
/ sizeof(WCHAR
)] == UNICODE_NULL
);
2225 Ret
= NtGdiAddFontResourceW(NtAbsPath
.Buffer
, NtAbsPath
.Length
/ sizeof(WCHAR
) + 1, 1, fl
, 0, pdv
);
2227 RtlFreeUnicodeString(&NtAbsPath
);
2237 AddFontMemResourceEx(
2244 if ( pbFont
&& cbFont
&& pcFonts
)
2246 return NtGdiAddFontMemResourceEx(pbFont
, cbFont
, NULL
, 0, pcFonts
);
2248 SetLastError(ERROR_INVALID_PARAMETER
);
2257 RemoveFontMemResourceEx(HANDLE fh
)
2261 return NtGdiRemoveFontMemResourceEx(fh
);
2263 SetLastError(ERROR_INVALID_PARAMETER
);
2273 AddFontResourceTracking(
2279 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2288 RemoveFontResourceTracking(LPCSTR lpString
,int unknown
)
2291 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2297 CreateScalableFontResourceW(
2299 LPCWSTR lpszFontRes
,
2300 LPCWSTR lpszFontFile
,
2301 LPCWSTR lpszCurrentPath
2308 /* fHidden=1 - only visible for the calling app, read-only, not
2309 * enumerated with EnumFonts/EnumFontFamilies
2310 * lpszCurrentPath can be NULL
2313 /* If the output file already exists, return the ERROR_FILE_EXISTS error as specified in MSDN */
2314 if ((f
= CreateFileW(lpszFontRes
, 0, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, 0)) != INVALID_HANDLE_VALUE
)
2317 SetLastError(ERROR_FILE_EXISTS
);
2320 return FALSE
; /* create failed */
2328 bInitSystemAndFontsDirectoriesW(LPWSTR
*SystemDir
,LPWSTR
*FontsDir
)
2331 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2340 EudcLoadLinkW(LPCWSTR pBaseFaceName
,LPCWSTR pEudcFontPath
,INT iPriority
,INT iFontLinkType
)
2343 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2352 EudcUnloadLinkW(LPCWSTR pBaseFaceName
,LPCWSTR pEudcFontPath
)
2355 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2364 GetEUDCTimeStamp(VOID
)
2366 return NtGdiGetEudcTimeStampEx(NULL
,0,TRUE
);
2374 GetEUDCTimeStampExW(LPWSTR lpBaseFaceName
)
2378 if (!lpBaseFaceName
)
2380 retValue
= NtGdiGetEudcTimeStampEx(NULL
,0,FALSE
);
2384 retValue
= NtGdiGetEudcTimeStampEx(lpBaseFaceName
, wcslen(lpBaseFaceName
), FALSE
);
2395 GetFontAssocStatus(HDC hdc
)
2401 retValue
= NtGdiQueryFontAssocInfo(hdc
);
2412 QueryFontAssocStatus(VOID
)
2415 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2424 UnloadNetworkFonts(DWORD unknown
)
2427 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2436 GetFontData(HDC hdc
,
2446 return NtGdiGetFontData(hdc
, dwTable
, dwOffset
, lpvBuffer
, cbData
);
2451 cGetTTFFromFOT(DWORD x1
,DWORD x2
,DWORD x3
, DWORD x4
, DWORD x5
, DWORD x6
, DWORD x7
)
2454 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);