2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/gdi32/object/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
->lpGlyphs
)
464 lstrcpynW( lpResults
->lpGlyphs
, lpString
, nSet
);
466 if(lpResults
->lpOrder
)
468 for(i
= 0; i
< nSet
; i
++)
469 lpResults
->lpOrder
[i
] = i
;
473 BIDI_Reorder( lpString, uCount, dwFlags, WINE_GCPW_FORCE_LTR, lpResults->lpOutString,
474 nSet, lpResults->lpOrder );
477 /* FIXME: Will use the placement chars */
481 for (i
= 0; i
< nSet
; i
++)
483 if (GetCharWidth32W(hdc
, lpString
[i
], lpString
[i
], &c
))
484 lpResults
->lpDx
[i
]= c
;
488 if (lpResults
->lpCaretPos
&& !(dwFlags
& GCP_REORDER
))
492 lpResults
->lpCaretPos
[0] = 0;
493 for (i
= 1; i
< nSet
; i
++)
494 if (GetTextExtentPoint32W(hdc
, &(lpString
[i
- 1]), 1, &size
))
495 lpResults
->lpCaretPos
[i
] = (pos
+= size
.cx
);
498 /*if(lpResults->lpGlyphs)
499 NtGdiGetGlyphIndicesW(hdc, lpString, nSet, lpResults->lpGlyphs, 0);*/
501 if (GetTextExtentPoint32W(hdc
, lpString
, uCount
, &size
))
502 ret
= MAKELONG(size
.cx
, size
.cy
);
509 NewGetCharacterPlacementW(
514 GCP_RESULTSW
*lpResults
,
521 if ( !lpString
|| uCount
<= 0 || (nMaxExtent
< 0 && nMaxExtent
!= -1 ) )
523 SetLastError(ERROR_INVALID_PARAMETER
);
529 if ( GetTextExtentPointW(hdc
, lpString
, uCount
, &Size
) )
531 return MAKELONG(Size
.cx
, Size
.cy
);
537 if ( nSet
> lpResults
->nGlyphs
)
538 nSet
= lpResults
->nGlyphs
;
540 return NtGdiGetCharacterPlacementW( hdc
,
554 GetCharABCWidthsFloatW(HDC hdc
,
559 DPRINT("GetCharABCWidthsFloatW\n");
560 if ((!abcF
) || (FirstChar
> LastChar
))
562 SetLastError(ERROR_INVALID_PARAMETER
);
565 return NtGdiGetCharABCWidthsW( hdc
,
567 (ULONG
)(LastChar
- FirstChar
+ 1),
579 GetCharWidthFloatW(HDC hdc
,
584 DPRINT("GetCharWidthsFloatW\n");
585 if ((!pxBuffer
) || (iFirstChar
> iLastChar
))
587 SetLastError(ERROR_INVALID_PARAMETER
);
590 return NtGdiGetCharWidthW( hdc
,
592 (ULONG
)(iLastChar
- iFirstChar
+ 1),
604 GetCharWidthW(HDC hdc
,
609 DPRINT("GetCharWidthsW\n");
610 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
612 SetLastError(ERROR_INVALID_PARAMETER
);
615 return NtGdiGetCharWidthW( hdc
,
617 (ULONG
)(iLastChar
- iFirstChar
+ 1),
629 GetCharWidth32W(HDC hdc
,
634 DPRINT("GetCharWidths32W\n");
635 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
637 SetLastError(ERROR_INVALID_PARAMETER
);
640 return NtGdiGetCharWidthW( hdc
,
642 (ULONG
)(iLastChar
- iFirstChar
+ 1),
644 GCW_NOFLOAT
|GCW_WIN32
,
655 GetCharABCWidthsW(HDC hdc
,
660 DPRINT("GetCharABCWidthsW\n");
661 if ((!lpabc
) || (FirstChar
> LastChar
))
663 SetLastError(ERROR_INVALID_PARAMETER
);
666 return NtGdiGetCharABCWidthsW( hdc
,
668 (ULONG
)(LastChar
- FirstChar
+ 1),
691 DPRINT("GetCharWidthsA\n");
693 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
697 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
700 HeapFree(GetProcessHeap(), 0, str
);
704 ret
= NtGdiGetCharWidthW( hdc
,
711 HeapFree(GetProcessHeap(), 0, str
);
712 HeapFree(GetProcessHeap(), 0, wstr
);
734 DPRINT("GetCharWidths32A\n");
736 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
740 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
743 HeapFree(GetProcessHeap(), 0, str
);
747 ret
= NtGdiGetCharWidthW( hdc
,
751 GCW_NOFLOAT
|GCW_WIN32
,
754 HeapFree(GetProcessHeap(), 0, str
);
755 HeapFree(GetProcessHeap(), 0, wstr
);
777 DPRINT("GetCharWidthsFloatA\n");
779 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
783 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
786 HeapFree(GetProcessHeap(), 0, str
);
789 ret
= NtGdiGetCharWidthW( hdc
, wstr
[0], (ULONG
) count
, (PWCHAR
) wstr
, 0, (PVOID
) pxBuffer
);
791 HeapFree(GetProcessHeap(), 0, str
);
792 HeapFree(GetProcessHeap(), 0, wstr
);
814 DPRINT("GetCharABCWidthsA\n");
816 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
820 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
823 HeapFree(GetProcessHeap(), 0, str
);
827 ret
= NtGdiGetCharABCWidthsW( hdc
,
834 HeapFree(GetProcessHeap(), 0, str
);
835 HeapFree(GetProcessHeap(), 0, wstr
);
845 GetCharABCWidthsFloatA(
857 DPRINT("GetCharABCWidthsFloatA\n");
859 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
863 wstr
= FONT_mbtowc( hdc
, str
, count
+1, &wlen
, NULL
);
866 HeapFree( GetProcessHeap(), 0, str
);
869 ret
= NtGdiGetCharABCWidthsW( hdc
,wstr
[0],(ULONG
)count
, (PWCHAR
)wstr
, 0, (PVOID
)lpABCF
);
871 HeapFree( GetProcessHeap(), 0, str
);
872 HeapFree( GetProcessHeap(), 0, wstr
);
882 GetCharABCWidthsI(HDC hdc
,
888 DPRINT("GetCharABCWidthsI\n");
889 return NtGdiGetCharABCWidthsW( hdc
,
893 GCABCW_NOFLOAT
|GCABCW_INDICES
,
902 GetCharWidthI(HDC hdc
,
909 DPRINT("GetCharWidthsI\n");
910 if (!lpBuffer
|| (!pgi
&& (giFirst
== MAXUSHORT
))) // Cannot be at max.
912 SetLastError(ERROR_INVALID_PARAMETER
);
915 if (!cgi
) return TRUE
;
916 return NtGdiGetCharWidthW( hdc
,
920 GCW_INDICES
|GCW_NOFLOAT
|GCW_WIN32
,
933 DWORD Gcp
= 0, Ret
= 0;
936 Ret
= NtGdiGetTextCharsetInfo(hDc
, NULL
, 0);
937 if ((Ret
== ARABIC_CHARSET
) || (Ret
== HEBREW_CHARSET
))
938 Ret
= (GCP_KASHIDA
|GCP_DIACRITIC
|GCP_LIGATE
|GCP_GLYPHSHAPE
|GCP_REORDER
);
940 Gcp
= GetDCDWord(hDc
, GdiGetFontLanguageInfo
, GCP_ERROR
);
941 if ( Gcp
== GCP_ERROR
)
965 lpstrW
= FONT_mbtowc(hdc
, lpstr
, count
, &countW
, NULL
);
970 Ret
= NtGdiGetGlyphIndicesW(hdc
, lpstrW
, countW
, pgi
, flags
);
971 HeapFree(GetProcessHeap(), 0, lpstrW
);
994 DPRINT("GetGlyphOutlineA uChar %x\n", uChar
);
995 if (!lpgm
|| !lpmat2
) return GDI_ERROR
;
996 if(!(uFormat
& GGO_GLYPH_INDEX
))
1000 if(uChar
> 0xff) /* but, 2 bytes character only */
1003 mbchs
[0] = (uChar
& 0xff00) >> 8;
1004 mbchs
[1] = (uChar
& 0xff);
1009 mbchs
[0] = (uChar
& 0xff);
1011 p
= FONT_mbtowc(hdc
, mbchs
, len
, NULL
, NULL
);
1016 ret
= NtGdiGetGlyphOutline(hdc
, c
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1017 HeapFree(GetProcessHeap(), 0, p
);
1031 LPGLYPHMETRICS lpgm
,
1037 DPRINT("GetGlyphOutlineW uChar %x\n", uChar
);
1038 if (!lpgm
|| !lpmat2
) return GDI_ERROR
;
1039 if (!lpvBuffer
) cbBuffer
= 0;
1040 return NtGdiGetGlyphOutline ( hdc
, uChar
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1059 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1068 GetOutlineTextMetricsA(
1071 LPOUTLINETEXTMETRICA lpOTM
1074 char buf
[512], *ptr
;
1076 OUTLINETEXTMETRICW
*lpOTMW
= (OUTLINETEXTMETRICW
*)buf
;
1077 OUTLINETEXTMETRICA
*output
= lpOTM
;
1080 if((ret
= GetOutlineTextMetricsW(hdc
, 0, NULL
)) == 0)
1082 if(ret
> sizeof(buf
))
1084 lpOTMW
= HeapAlloc(GetProcessHeap(), 0, ret
);
1090 GetOutlineTextMetricsW(hdc
, ret
, lpOTMW
);
1092 needed
= sizeof(OUTLINETEXTMETRICA
);
1093 if(lpOTMW
->otmpFamilyName
)
1094 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1095 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1096 NULL
, 0, NULL
, NULL
);
1097 if(lpOTMW
->otmpFaceName
)
1098 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1099 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1100 NULL
, 0, NULL
, NULL
);
1101 if(lpOTMW
->otmpStyleName
)
1102 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1103 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1104 NULL
, 0, NULL
, NULL
);
1105 if(lpOTMW
->otmpFullName
)
1106 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1107 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1108 NULL
, 0, NULL
, NULL
);
1116 DPRINT("needed = %u\n", needed
);
1119 /* Since the supplied buffer isn't big enough, we'll alloc one
1120 that is and memcpy the first cbData bytes into the lpOTM at
1122 output
= HeapAlloc(GetProcessHeap(), 0, needed
);
1129 ret
= output
->otmSize
= min(needed
, cbData
);
1130 FONT_TextMetricWToA( &lpOTMW
->otmTextMetrics
, &output
->otmTextMetrics
);
1131 output
->otmFiller
= 0;
1132 output
->otmPanoseNumber
= lpOTMW
->otmPanoseNumber
;
1133 output
->otmfsSelection
= lpOTMW
->otmfsSelection
;
1134 output
->otmfsType
= lpOTMW
->otmfsType
;
1135 output
->otmsCharSlopeRise
= lpOTMW
->otmsCharSlopeRise
;
1136 output
->otmsCharSlopeRun
= lpOTMW
->otmsCharSlopeRun
;
1137 output
->otmItalicAngle
= lpOTMW
->otmItalicAngle
;
1138 output
->otmEMSquare
= lpOTMW
->otmEMSquare
;
1139 output
->otmAscent
= lpOTMW
->otmAscent
;
1140 output
->otmDescent
= lpOTMW
->otmDescent
;
1141 output
->otmLineGap
= lpOTMW
->otmLineGap
;
1142 output
->otmsCapEmHeight
= lpOTMW
->otmsCapEmHeight
;
1143 output
->otmsXHeight
= lpOTMW
->otmsXHeight
;
1144 output
->otmrcFontBox
= lpOTMW
->otmrcFontBox
;
1145 output
->otmMacAscent
= lpOTMW
->otmMacAscent
;
1146 output
->otmMacDescent
= lpOTMW
->otmMacDescent
;
1147 output
->otmMacLineGap
= lpOTMW
->otmMacLineGap
;
1148 output
->otmusMinimumPPEM
= lpOTMW
->otmusMinimumPPEM
;
1149 output
->otmptSubscriptSize
= lpOTMW
->otmptSubscriptSize
;
1150 output
->otmptSubscriptOffset
= lpOTMW
->otmptSubscriptOffset
;
1151 output
->otmptSuperscriptSize
= lpOTMW
->otmptSuperscriptSize
;
1152 output
->otmptSuperscriptOffset
= lpOTMW
->otmptSuperscriptOffset
;
1153 output
->otmsStrikeoutSize
= lpOTMW
->otmsStrikeoutSize
;
1154 output
->otmsStrikeoutPosition
= lpOTMW
->otmsStrikeoutPosition
;
1155 output
->otmsUnderscoreSize
= lpOTMW
->otmsUnderscoreSize
;
1156 output
->otmsUnderscorePosition
= lpOTMW
->otmsUnderscorePosition
;
1159 ptr
= (char*)(output
+ 1);
1160 left
= needed
- sizeof(*output
);
1162 if(lpOTMW
->otmpFamilyName
)
1164 output
->otmpFamilyName
= (LPSTR
)(ptr
- (char*)output
);
1165 len
= WideCharToMultiByte(CP_ACP
, 0,
1166 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1167 ptr
, left
, NULL
, NULL
);
1172 output
->otmpFamilyName
= 0;
1174 if(lpOTMW
->otmpFaceName
)
1176 output
->otmpFaceName
= (LPSTR
)(ptr
- (char*)output
);
1177 len
= WideCharToMultiByte(CP_ACP
, 0,
1178 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1179 ptr
, left
, NULL
, NULL
);
1184 output
->otmpFaceName
= 0;
1186 if(lpOTMW
->otmpStyleName
)
1188 output
->otmpStyleName
= (LPSTR
)(ptr
- (char*)output
);
1189 len
= WideCharToMultiByte(CP_ACP
, 0,
1190 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1191 ptr
, left
, NULL
, NULL
);
1196 output
->otmpStyleName
= 0;
1198 if(lpOTMW
->otmpFullName
)
1200 output
->otmpFullName
= (LPSTR
)(ptr
- (char*)output
);
1201 len
= WideCharToMultiByte(CP_ACP
, 0,
1202 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1203 ptr
, left
, NULL
, NULL
);
1207 output
->otmpFullName
= 0;
1213 memcpy(lpOTM
, output
, cbData
);
1214 HeapFree(GetProcessHeap(), 0, output
);
1216 /* check if the string offsets really fit into the provided size */
1217 /* FIXME: should we check string length as well? */
1218 if ((UINT_PTR
)lpOTM
->otmpFamilyName
>= lpOTM
->otmSize
)
1219 lpOTM
->otmpFamilyName
= 0; /* doesn't fit */
1221 if ((UINT_PTR
)lpOTM
->otmpFaceName
>= lpOTM
->otmSize
)
1222 lpOTM
->otmpFaceName
= 0; /* doesn't fit */
1224 if ((UINT_PTR
)lpOTM
->otmpStyleName
>= lpOTM
->otmSize
)
1225 lpOTM
->otmpStyleName
= 0; /* doesn't fit */
1227 if ((UINT_PTR
)lpOTM
->otmpFullName
>= lpOTM
->otmSize
)
1228 lpOTM
->otmpFullName
= 0; /* doesn't fit */
1232 if(lpOTMW
!= (OUTLINETEXTMETRICW
*)buf
)
1233 HeapFree(GetProcessHeap(), 0, lpOTMW
);
1238 /* Performs a device to world transformation on the specified size (which
1239 * is in integer format).
1241 static inline INT
INTERNAL_YDSTOWS(XFORM
*xForm
, INT height
)
1245 /* Perform operation with floating point */
1246 floatHeight
= (double)height
* xForm
->eM22
;
1247 /* Round to integers */
1248 return GDI_ROUND(floatHeight
);
1251 /* scale width and height but don't mirror them */
1252 static inline INT
width_to_LP( XFORM
*xForm
, INT width
)
1254 return GDI_ROUND( (double)width
* fabs( xForm
->eM11
));
1257 static inline INT
height_to_LP( XFORM
*xForm
, INT height
)
1259 return GDI_ROUND( (double)height
* fabs( xForm
->eM22
));
1267 GetOutlineTextMetricsW(
1270 LPOUTLINETEXTMETRICW lpOTM
1273 TMDIFF Tmd
; // Should not be zero.
1274 UINT Size
, AvailableSize
= 0, StringSize
;
1276 OUTLINETEXTMETRICW
* LocalOTM
;
1280 /* Get the structure */
1281 Size
= NtGdiGetOutlineTextMetricsInternalW(hdc
, 0, NULL
, &Tmd
);
1284 if (!lpOTM
|| (cbData
< sizeof(*lpOTM
)))
1287 LocalOTM
= HeapAlloc(GetProcessHeap(), 0, Size
);
1288 LocalOTM
->otmSize
= Size
;
1289 Size
= NtGdiGetOutlineTextMetricsInternalW(hdc
, Size
, LocalOTM
, &Tmd
);
1292 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1296 if (!NtGdiGetTransform(hdc
, GdiDeviceSpaceToWorldSpace
, &DevToWorld
))
1298 DPRINT1("NtGdiGetTransform failed!\n");
1299 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1300 SetLastError(ERROR_INVALID_HANDLE
);
1304 /* Fill in DC specific data */
1305 LocalOTM
->otmTextMetrics
.tmDigitizedAspectX
= GetDeviceCaps(hdc
, LOGPIXELSX
);
1306 LocalOTM
->otmTextMetrics
.tmDigitizedAspectY
= GetDeviceCaps(hdc
, LOGPIXELSY
);
1307 LocalOTM
->otmTextMetrics
.tmHeight
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmHeight
);
1308 LocalOTM
->otmTextMetrics
.tmAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmAscent
);
1309 LocalOTM
->otmTextMetrics
.tmDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmDescent
);
1310 LocalOTM
->otmTextMetrics
.tmInternalLeading
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmInternalLeading
);
1311 LocalOTM
->otmTextMetrics
.tmExternalLeading
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmExternalLeading
);
1312 LocalOTM
->otmTextMetrics
.tmAveCharWidth
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmAveCharWidth
);
1313 LocalOTM
->otmTextMetrics
.tmMaxCharWidth
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmMaxCharWidth
);
1314 LocalOTM
->otmTextMetrics
.tmOverhang
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmOverhang
);
1315 LocalOTM
->otmAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmAscent
);
1316 LocalOTM
->otmDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmDescent
);
1317 LocalOTM
->otmLineGap
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmLineGap
));
1318 LocalOTM
->otmsCapEmHeight
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsCapEmHeight
));
1319 LocalOTM
->otmsXHeight
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsXHeight
));
1320 LocalOTM
->otmrcFontBox
.top
= height_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.top
);
1321 LocalOTM
->otmrcFontBox
.bottom
= height_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.bottom
);
1322 LocalOTM
->otmrcFontBox
.left
= width_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.left
);
1323 LocalOTM
->otmrcFontBox
.right
= width_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.right
);
1324 LocalOTM
->otmMacAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmMacAscent
);
1325 LocalOTM
->otmMacDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmMacDescent
);
1326 LocalOTM
->otmMacLineGap
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmMacLineGap
));
1327 LocalOTM
->otmptSubscriptSize
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptSize
.x
);
1328 LocalOTM
->otmptSubscriptSize
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptSize
.y
);
1329 LocalOTM
->otmptSubscriptOffset
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptOffset
.x
);
1330 LocalOTM
->otmptSubscriptOffset
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptOffset
.y
);
1331 LocalOTM
->otmptSuperscriptSize
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptSize
.x
);
1332 LocalOTM
->otmptSuperscriptSize
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptSize
.y
);
1333 LocalOTM
->otmptSuperscriptOffset
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptOffset
.x
);
1334 LocalOTM
->otmptSuperscriptOffset
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptOffset
.y
);
1335 LocalOTM
->otmsStrikeoutSize
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsStrikeoutSize
));
1336 LocalOTM
->otmsStrikeoutPosition
= height_to_LP( &DevToWorld
, LocalOTM
->otmsStrikeoutPosition
);
1337 LocalOTM
->otmsUnderscoreSize
= height_to_LP( &DevToWorld
, LocalOTM
->otmsUnderscoreSize
);
1338 LocalOTM
->otmsUnderscorePosition
= height_to_LP( &DevToWorld
, LocalOTM
->otmsUnderscorePosition
);
1340 /* Copy what we can */
1341 CopyMemory(lpOTM
, LocalOTM
, min(Size
, cbData
));
1343 lpOTM
->otmpFamilyName
= NULL
;
1344 lpOTM
->otmpFaceName
= NULL
;
1345 lpOTM
->otmpStyleName
= NULL
;
1346 lpOTM
->otmpFullName
= NULL
;
1348 Size
= sizeof(*lpOTM
);
1349 AvailableSize
= cbData
- Size
;
1350 Ptr
= (BYTE
*)lpOTM
+ sizeof(*lpOTM
);
1352 /* Fix string values up */
1353 if (LocalOTM
->otmpFamilyName
)
1355 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFamilyName
);
1356 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1357 if (AvailableSize
>= StringSize
)
1359 CopyMemory(Ptr
, Str
, StringSize
);
1360 lpOTM
->otmpFamilyName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1362 AvailableSize
-= StringSize
;
1367 if (LocalOTM
->otmpFaceName
)
1369 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFaceName
);
1370 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1371 if (AvailableSize
>= StringSize
)
1373 CopyMemory(Ptr
, Str
, StringSize
);
1374 lpOTM
->otmpFaceName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1376 AvailableSize
-= StringSize
;
1381 if (LocalOTM
->otmpStyleName
)
1383 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpStyleName
);
1384 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1385 if (AvailableSize
>= StringSize
)
1387 CopyMemory(Ptr
, Str
, StringSize
);
1388 lpOTM
->otmpStyleName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1390 AvailableSize
-= StringSize
;
1395 if (LocalOTM
->otmpFullName
)
1397 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFullName
);
1398 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1399 if (AvailableSize
>= StringSize
)
1401 CopyMemory(Ptr
, Str
, StringSize
);
1402 lpOTM
->otmpFullName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1404 AvailableSize
-= StringSize
;
1409 lpOTM
->otmSize
= Size
;
1411 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1421 GetKerningPairsW(HDC hdc
,
1423 LPKERNINGPAIR pkpDst
)
1425 if ((cPairs
!= 0) || (pkpDst
== 0))
1427 return NtGdiGetKerningPairs(hdc
,cPairs
,pkpDst
);
1431 SetLastError(ERROR_INVALID_PARAMETER
);
1441 GetKerningPairsA( HDC hDC
,
1443 LPKERNINGPAIR kern_pairA
)
1448 DWORD i
, total_kern_pairs
, kern_pairs_copied
= 0;
1449 KERNINGPAIR
*kern_pairW
;
1451 if (!cPairs
&& kern_pairA
)
1453 SetLastError(ERROR_INVALID_PARAMETER
);
1457 charset
= GetTextCharset(hDC
);
1458 if (!TranslateCharsetInfo(ULongToPtr(charset
), &csi
, TCI_SRCCHARSET
))
1460 DPRINT1("Can't find codepage for charset %d\n", charset
);
1463 /* GetCPInfo() will fail on CP_SYMBOL, and WideCharToMultiByte is supposed
1464 * to fail on an invalid character for CP_SYMBOL.
1466 cpi
.DefaultChar
[0] = 0;
1467 if (csi
.ciACP
!= CP_SYMBOL
&& !GetCPInfo(csi
.ciACP
, &cpi
))
1469 DPRINT1("Can't find codepage %u info\n", csi
.ciACP
);
1472 DPRINT("charset %d => codepage %u\n", charset
, csi
.ciACP
);
1474 total_kern_pairs
= NtGdiGetKerningPairs(hDC
, 0, NULL
);
1475 if (!total_kern_pairs
) return 0;
1477 if (!cPairs
&& !kern_pairA
) return total_kern_pairs
;
1479 kern_pairW
= HeapAlloc(GetProcessHeap(), 0, total_kern_pairs
* sizeof(*kern_pairW
));
1480 if (kern_pairW
== NULL
)
1484 GetKerningPairsW(hDC
, total_kern_pairs
, kern_pairW
);
1486 for (i
= 0; i
< total_kern_pairs
; i
++)
1490 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wFirst
, 1, &first
, 1, NULL
, NULL
))
1493 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wSecond
, 1, &second
, 1, NULL
, NULL
))
1496 if (first
== cpi
.DefaultChar
[0] || second
== cpi
.DefaultChar
[0])
1501 if (kern_pairs_copied
>= cPairs
) break;
1503 kern_pairA
->wFirst
= (BYTE
)first
;
1504 kern_pairA
->wSecond
= (BYTE
)second
;
1505 kern_pairA
->iKernAmount
= kern_pairW
[i
].iKernAmount
;
1508 kern_pairs_copied
++;
1511 HeapFree(GetProcessHeap(), 0, kern_pairW
);
1513 return kern_pairs_copied
;
1523 CreateFontIndirectExA(const ENUMLOGFONTEXDVA
*elfexd
)
1527 ENUMLOGFONTEXDVW Logfont
;
1529 EnumLogFontExW2A( (LPENUMLOGFONTEXA
) elfexd
,
1530 &Logfont
.elfEnumLogfontEx
);
1532 RtlCopyMemory( &Logfont
.elfDesignVector
,
1533 (PVOID
) &elfexd
->elfDesignVector
,
1534 sizeof(DESIGNVECTOR
));
1536 return NtGdiHfontCreate( &Logfont
, 0, 0, 0, NULL
);
1547 CreateFontIndirectExW(const ENUMLOGFONTEXDVW
*elfexd
)
1549 /* Msdn: Note, this function ignores the elfDesignVector member in
1554 return NtGdiHfontCreate((PENUMLOGFONTEXDVW
) elfexd
, 0, 0, 0, NULL
);
1565 CreateFontIndirectA(
1566 CONST LOGFONTA
*lplf
1573 LogFontA2W(&tlf
, lplf
);
1574 return CreateFontIndirectW(&tlf
);
1585 CreateFontIndirectW(
1586 CONST LOGFONTW
*lplf
1591 ENUMLOGFONTEXDVW Logfont
;
1593 RtlCopyMemory( &Logfont
.elfEnumLogfontEx
.elfLogFont
, lplf
, sizeof(LOGFONTW
));
1594 // Need something other than just cleaning memory here.
1595 // Guess? Use caller data to determine the rest.
1596 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfFullName
,
1597 sizeof(Logfont
.elfEnumLogfontEx
.elfFullName
));
1598 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfStyle
,
1599 sizeof(Logfont
.elfEnumLogfontEx
.elfStyle
));
1600 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfScript
,
1601 sizeof(Logfont
.elfEnumLogfontEx
.elfScript
));
1603 Logfont
.elfDesignVector
.dvNumAxes
= 0; // No more than MM_MAX_NUMAXES
1605 RtlZeroMemory( &Logfont
.elfDesignVector
, sizeof(DESIGNVECTOR
));
1607 return CreateFontIndirectExW(&Logfont
);
1628 DWORD fdwOutputPrecision
,
1629 DWORD fdwClipPrecision
,
1631 DWORD fdwPitchAndFamily
,
1635 ANSI_STRING StringA
;
1636 UNICODE_STRING StringU
;
1639 RtlInitAnsiString(&StringA
, (LPSTR
)lpszFace
);
1640 RtlAnsiStringToUnicodeString(&StringU
, &StringA
, TRUE
);
1642 ret
= CreateFontW(nHeight
,
1657 RtlFreeUnicodeString(&StringU
);
1678 DWORD fdwOutputPrecision
,
1679 DWORD fdwClipPrecision
,
1681 DWORD fdwPitchAndFamily
,
1687 logfont
.lfHeight
= nHeight
;
1688 logfont
.lfWidth
= nWidth
;
1689 logfont
.lfEscapement
= nEscapement
;
1690 logfont
.lfOrientation
= nOrientation
;
1691 logfont
.lfWeight
= nWeight
;
1692 logfont
.lfItalic
= (BYTE
)fnItalic
;
1693 logfont
.lfUnderline
= (BYTE
)fdwUnderline
;
1694 logfont
.lfStrikeOut
= (BYTE
)fdwStrikeOut
;
1695 logfont
.lfCharSet
= (BYTE
)fdwCharSet
;
1696 logfont
.lfOutPrecision
= (BYTE
)fdwOutputPrecision
;
1697 logfont
.lfClipPrecision
= (BYTE
)fdwClipPrecision
;
1698 logfont
.lfQuality
= (BYTE
)fdwQuality
;
1699 logfont
.lfPitchAndFamily
= (BYTE
)fdwPitchAndFamily
;
1701 if (NULL
!= lpszFace
)
1703 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
1704 wcsncpy((wchar_t *)logfont
.lfFaceName
, lpszFace
, Size
- 1);
1705 /* Be 101% sure to have '\0' at end of string */
1706 logfont
.lfFaceName
[Size
- 1] = '\0';
1710 logfont
.lfFaceName
[0] = L
'\0';
1713 return CreateFontIndirectW(&logfont
);
1722 CreateScalableFontResourceA(
1725 LPCSTR lpszFontFile
,
1726 LPCSTR lpszCurrentPath
1738 AddFontResourceExW ( LPCWSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1740 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1742 SetLastError( ERROR_INVALID_PARAMETER
);
1746 return GdiAddFontResourceW(lpszFilename
, fl
,0);
1755 AddFontResourceExA ( LPCSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1761 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1763 SetLastError( ERROR_INVALID_PARAMETER
);
1767 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1768 if ( !NT_SUCCESS (Status
) )
1770 SetLastError (RtlNtStatusToDosError(Status
));
1774 rc
= GdiAddFontResourceW ( FilenameW
, fl
, 0 );
1775 HEAP_free ( FilenameW
);
1785 AddFontResourceA ( LPCSTR lpszFilename
)
1791 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1792 if ( !NT_SUCCESS (Status
) )
1794 SetLastError (RtlNtStatusToDosError(Status
));
1798 rc
= GdiAddFontResourceW ( FilenameW
, 0, 0);
1800 HEAP_free ( FilenameW
);
1811 AddFontResourceW ( LPCWSTR lpszFilename
)
1813 return GdiAddFontResourceW ( lpszFilename
, 0, 0 );
1822 RemoveFontResourceW(LPCWSTR lpFileName
)
1824 return RemoveFontResourceExW(lpFileName
,0,0);
1833 RemoveFontResourceA(LPCSTR lpFileName
)
1835 return RemoveFontResourceExA(lpFileName
,0,0);
1843 RemoveFontResourceExA(LPCSTR lpFileName
,
1851 /* FIXME the flags */
1853 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1855 Status
= HEAP_strdupA2W ( &lpFileNameW
, lpFileName
);
1856 if (!NT_SUCCESS (Status
))
1857 SetLastError (RtlNtStatusToDosError(Status
));
1861 HEAP_free ( lpFileNameW
);
1872 RemoveFontResourceExW(LPCWSTR lpFileName
,
1876 /* FIXME the flags */
1878 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1883 /***********************************************************************
1884 * GdiGetCharDimensions
1886 * Gets the average width of the characters in the English alphabet.
1889 * hdc [I] Handle to the device context to measure on.
1890 * lptm [O] Pointer to memory to store the text metrics into.
1891 * height [O] On exit, the maximum height of characters in the English alphabet.
1894 * The average width of characters in the English alphabet.
1897 * This function is used by the dialog manager to get the size of a dialog
1898 * unit. It should also be used by other pieces of code that need to know
1899 * the size of a dialog unit in logical units without having access to the
1900 * window handle of the dialog.
1901 * Windows caches the font metrics from this function, but we don't and
1902 * there doesn't appear to be an immediate advantage to do so.
1905 * GetTextExtentPointW, GetTextMetricsW, MapDialogRect.
1907 * Despite most of MSDN insisting that the horizontal base unit is
1908 * tmAveCharWidth it isn't. Knowledge base article Q145994
1909 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
1910 * says that we should take the average of the 52 English upper and lower
1918 GdiGetCharDimensions(HDC hdc
, LPTEXTMETRICW lptm
, LONG
*height
)
1922 static const WCHAR alphabet
[] =
1924 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
1925 'r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H',
1926 'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',0
1929 if(!GetTextMetricsW(hdc
, &tm
)) return 0;
1931 if(!GetTextExtentPointW(hdc
, alphabet
, 52, &sz
)) return 0;
1933 if (lptm
) *lptm
= tm
;
1934 if (height
) *height
= tm
.tmHeight
;
1936 return (sz
.cx
/ 26 + 1) / 2;
1939 /*************************************************************************
1940 * TranslateCharsetInfo [GDI32.@]
1942 * Fills a CHARSETINFO structure for a character set, code page, or
1943 * font. This allows making the correspondance between different labelings
1944 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1945 * of the same encoding.
1947 * Only one codepage will be set in lpCs->fs. If TCI_SRCFONTSIG is used,
1948 * only one codepage should be set in *lpSrc.
1951 * TRUE on success, FALSE on failure.
1959 TranslateCharsetInfo(
1960 LPDWORD lpSrc
, /* [in]
1961 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1962 if flags == TCI_SRCCHARSET: a character set value
1963 if flags == TCI_SRCCODEPAGE: a code page value
1965 LPCHARSETINFO lpCs
, /* [out] structure to receive charset information */
1966 DWORD flags
/* [in] determines interpretation of lpSrc */)
1971 case TCI_SRCFONTSIG
:
1972 while (index
< MAXTCIINDEX
&& !(*lpSrc
>>index
& 0x0001)) index
++;
1974 case TCI_SRCCODEPAGE
:
1975 while (index
< MAXTCIINDEX
&& PtrToUlong(lpSrc
) != FONT_tci
[index
].ciACP
) index
++;
1977 case TCI_SRCCHARSET
:
1978 while (index
< MAXTCIINDEX
&& PtrToUlong(lpSrc
) != FONT_tci
[index
].ciCharset
) index
++;
1982 LCID lCid
= (LCID
)PtrToUlong(lpSrc
);
1983 LOCALESIGNATURE LocSig
;
1984 INT Ret
= GetLocaleInfoW(lCid
, LOCALE_FONTSIGNATURE
, (LPWSTR
)&LocSig
, 0);
1985 if ( GetLocaleInfoW(lCid
, LOCALE_FONTSIGNATURE
, (LPWSTR
)&LocSig
, Ret
))
1987 while (index
< MAXTCIINDEX
&& !(LocSig
.lsCsbDefault
[0]>>index
& 0x0001)) index
++;
1992 GdiSetLastError(ERROR_INVALID_PARAMETER
);
1995 if (index
>= MAXTCIINDEX
|| FONT_tci
[index
].ciCharset
== DEFAULT_CHARSET
) return FALSE
;
1996 DPRINT("Index %d Charset %u CodePage %u FontSig %lu\n",
1997 index
,FONT_tci
[index
].ciCharset
,FONT_tci
[index
].ciACP
,FONT_tci
[index
].fs
.fsCsb
[0]);
1998 memcpy(lpCs
, &FONT_tci
[index
], sizeof(CHARSETINFO
));
2013 DWORD Ret
= GDI_ERROR
;
2016 if (GDI_HANDLE_GET_TYPE(hDC
) != GDI_OBJECT_TYPE_DC
)
2018 if (GDI_HANDLE_GET_TYPE(hDC
) == GDI_OBJECT_TYPE_METADC
)
2019 return MFDRV_SetMapperFlags( hDC
, flags
);
2022 PLDC pLDC
= Dc_Attr
->pvLDC
;
2025 SetLastError(ERROR_INVALID_HANDLE
);
2028 if (pLDC
->iType
== LDC_EMFLDC
)
2030 return EMFDRV_SetMapperFlags( hDC
, flags
);
2035 if (!GdiGetHandleUserData((HGDIOBJ
) hDC
, GDI_OBJECT_TYPE_DC
, (PVOID
) &Dc_Attr
)) return GDI_ERROR
;
2037 if (NtCurrentTeb()->GdiTebBatch
.HDC
== hDC
)
2039 if (Dc_Attr
->ulDirty_
& DC_FONTTEXT_DIRTY
)
2042 Dc_Attr
->ulDirty_
&= ~(DC_MODE_DIRTY
|DC_FONTTEXT_DIRTY
);
2047 SetLastError(ERROR_INVALID_PARAMETER
);
2050 Ret
= Dc_Attr
->flFontMapper
;
2051 Dc_Attr
->flFontMapper
= flags
;
2065 FONTENUMPROCW FontFunc
,
2070 return NtGdiEnumFonts ( hDC
, lpFaceName
, FontFunc
, lParam
);
2072 return EnumFontFamiliesW( hDC
, lpFaceName
, FontFunc
, lParam
);
2084 FONTENUMPROCA FontFunc
,
2093 Status
= HEAP_strdupA2W ( &lpFaceNameW
, lpFaceName
);
2094 if (!NT_SUCCESS (Status
))
2095 SetLastError (RtlNtStatusToDosError(Status
));
2098 rc
= NtGdiEnumFonts ( hDC
, lpFaceNameW
, FontFunc
, lParam
);
2100 HEAP_free ( lpFaceNameW
);
2104 return EnumFontFamiliesA( hDC
, lpFaceName
, FontFunc
, lParam
);
2108 #define EfdFontFamilies 3
2112 NewEnumFontFamiliesExW(
2114 LPLOGFONTW lpLogfont
,
2115 FONTENUMPROCW lpEnumFontFamExProcW
,
2119 ULONG_PTR idEnum
, cbDataSize
, cbRetSize
;
2120 PENUMFONTDATAW pEfdw
;
2125 /* Open enumeration handle and find out how much memory we need */
2126 idEnum
= NtGdiEnumFontOpen(hDC
,
2130 (lpLogfont
&& lpLogfont
->lfFaceName
[0])? lpLogfont
->lfFaceName
: NULL
,
2131 lpLogfont
? lpLogfont
->lfCharSet
: DEFAULT_CHARSET
,
2137 if (cbDataSize
== 0)
2139 NtGdiEnumFontClose(idEnum
);
2143 /* Allocate memory */
2144 pBuffer
= HeapAlloc(GetProcessHeap(), 0, cbDataSize
);
2145 if (pBuffer
== NULL
)
2147 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2148 NtGdiEnumFontClose(idEnum
);
2152 /* Do the enumeration */
2153 if (!NtGdiEnumFontChunk(hDC
, idEnum
, cbDataSize
, &cbRetSize
, (PVOID
)pBuffer
))
2155 HeapFree(GetProcessHeap(), 0, pBuffer
);
2156 NtGdiEnumFontClose(idEnum
);
2160 /* Get start and end address */
2161 pEfdw
= (PENUMFONTDATAW
)pBuffer
;
2162 pMax
= pBuffer
+ cbDataSize
;
2164 /* Iterate through the structures */
2165 while ((PBYTE
)pEfdw
< pMax
&& ret
)
2167 PNTMW_INTERNAL pNtmwi
= (PNTMW_INTERNAL
)((ULONG_PTR
)pEfdw
+ pEfdw
->ulNtmwiOffset
);
2169 ret
= lpEnumFontFamExProcW((VOID
*)&pEfdw
->elfexdv
.elfEnumLogfontEx
,
2170 (VOID
*)&pNtmwi
->ntmw
,
2174 pEfdw
= (PENUMFONTDATAW
)((ULONG_PTR
)pEfdw
+ pEfdw
->cbSize
);
2177 /* Release the memory and close handle */
2178 HeapFree(GetProcessHeap(), 0, pBuffer
);
2179 NtGdiEnumFontClose(idEnum
);
2189 GdiAddFontResourceW(
2190 LPCWSTR lpszFilename
,
2195 WCHAR lpszBuffer
[MAX_PATH
];
2196 WCHAR lpszAbsPath
[MAX_PATH
];
2197 UNICODE_STRING NtAbsPath
;
2199 /* FIXME: We don't support multiple files passed in lpszFilename
2200 * as L"abcxxxxx.pfm|abcxxxxx.pfb"
2203 /* Does the file exist in CurrentDirectory or in the Absolute Path passed? */
2204 GetCurrentDirectoryW(MAX_PATH
, lpszBuffer
);
2206 if (!SearchPathW(lpszBuffer
, lpszFilename
, NULL
, MAX_PATH
, lpszAbsPath
, NULL
))
2208 /* Nope. Then let's check Fonts folder */
2209 GetWindowsDirectoryW(lpszBuffer
, MAX_PATH
);
2210 StringCbCatW(lpszBuffer
, sizeof(lpszBuffer
), L
"\\Fonts");
2212 if (!SearchPathW(lpszBuffer
, lpszFilename
, NULL
, MAX_PATH
, lpszAbsPath
, NULL
))
2214 DPRINT1("Font not found. The Buffer is: %ls, the FileName is: %S\n", lpszBuffer
, lpszFilename
);
2219 /* We found the font file so: */
2220 if (!RtlDosPathNameToNtPathName_U(lpszAbsPath
, &NtAbsPath
, NULL
, NULL
))
2222 DPRINT1("Can't convert Path! Path: %ls\n", lpszAbsPath
);
2226 /* The Nt call expects a null-terminator included in cwc param. */
2227 ASSERT(NtAbsPath
.Buffer
[NtAbsPath
.Length
/ sizeof(WCHAR
)] == UNICODE_NULL
);
2228 Ret
= NtGdiAddFontResourceW(NtAbsPath
.Buffer
, NtAbsPath
.Length
/ sizeof(WCHAR
) + 1, 1, fl
, 0, pdv
);
2230 RtlFreeUnicodeString(&NtAbsPath
);
2240 AddFontMemResourceEx(
2247 if ( pbFont
&& cbFont
&& pcFonts
)
2249 return NtGdiAddFontMemResourceEx(pbFont
, cbFont
, NULL
, 0, pcFonts
);
2251 SetLastError(ERROR_INVALID_PARAMETER
);
2260 RemoveFontMemResourceEx(HANDLE fh
)
2264 return NtGdiRemoveFontMemResourceEx(fh
);
2266 SetLastError(ERROR_INVALID_PARAMETER
);
2276 AddFontResourceTracking(
2282 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2291 RemoveFontResourceTracking(LPCSTR lpString
,int unknown
)
2294 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2300 CreateScalableFontResourceW(
2302 LPCWSTR lpszFontRes
,
2303 LPCWSTR lpszFontFile
,
2304 LPCWSTR lpszCurrentPath
2311 /* fHidden=1 - only visible for the calling app, read-only, not
2312 * enumerated with EnumFonts/EnumFontFamilies
2313 * lpszCurrentPath can be NULL
2316 /* If the output file already exists, return the ERROR_FILE_EXISTS error as specified in MSDN */
2317 if ((f
= CreateFileW(lpszFontRes
, 0, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, 0)) != INVALID_HANDLE_VALUE
)
2320 SetLastError(ERROR_FILE_EXISTS
);
2323 return FALSE
; /* create failed */
2331 bInitSystemAndFontsDirectoriesW(LPWSTR
*SystemDir
,LPWSTR
*FontsDir
)
2334 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2343 EudcLoadLinkW(LPCWSTR pBaseFaceName
,LPCWSTR pEudcFontPath
,INT iPriority
,INT iFontLinkType
)
2346 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2355 EudcUnloadLinkW(LPCWSTR pBaseFaceName
,LPCWSTR pEudcFontPath
)
2358 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2367 GetEUDCTimeStamp(VOID
)
2369 return NtGdiGetEudcTimeStampEx(NULL
,0,TRUE
);
2377 GetEUDCTimeStampExW(LPWSTR lpBaseFaceName
)
2381 if (!lpBaseFaceName
)
2383 retValue
= NtGdiGetEudcTimeStampEx(NULL
,0,FALSE
);
2387 retValue
= NtGdiGetEudcTimeStampEx(lpBaseFaceName
, wcslen(lpBaseFaceName
), FALSE
);
2398 GetFontAssocStatus(HDC hdc
)
2404 retValue
= NtGdiQueryFontAssocInfo(hdc
);
2415 QueryFontAssocStatus(VOID
)
2418 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2427 UnloadNetworkFonts(DWORD unknown
)
2430 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2439 GetFontData(HDC hdc
,
2449 return NtGdiGetFontData(hdc
, dwTable
, dwOffset
, lpvBuffer
, cbData
);
2454 cGetTTFFromFOT(DWORD x1
,DWORD x2
,DWORD x3
, DWORD x4
, DWORD x5
, DWORD x6
, DWORD x7
)
2457 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);