2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/gdi32/object/font.c
17 /* Rounds a floating point number to integer. The world-to-viewport
18 * transformation process is done in floating point internally. This function
19 * is then used to round these coordinates to integer values.
21 static __inline INT
GDI_ROUND(FLOAT val
)
23 return (int)floor(val
+ 0.5);
27 * For TranslateCharsetInfo
29 #define MAXTCIINDEX 32
30 static const CHARSETINFO FONT_tci
[MAXTCIINDEX
] =
33 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
34 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
35 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
36 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
37 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
38 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
39 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
40 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
41 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
42 /* reserved by ANSI */
43 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
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}} },
51 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
52 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
53 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
54 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
55 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
56 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
57 /* reserved for alternate ANSI and OEM */
58 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
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 /* reserved for system */
67 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
68 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
71 #define INITIAL_FAMILY_COUNT 64
73 /***********************************************************************
74 * TEXTMETRIC conversion functions.
78 FONT_TextMetricWToA(const TEXTMETRICW
*ptmW
, LPTEXTMETRICA ptmA
)
80 ptmA
->tmHeight
= ptmW
->tmHeight
;
81 ptmA
->tmAscent
= ptmW
->tmAscent
;
82 ptmA
->tmDescent
= ptmW
->tmDescent
;
83 ptmA
->tmInternalLeading
= ptmW
->tmInternalLeading
;
84 ptmA
->tmExternalLeading
= ptmW
->tmExternalLeading
;
85 ptmA
->tmAveCharWidth
= ptmW
->tmAveCharWidth
;
86 ptmA
->tmMaxCharWidth
= ptmW
->tmMaxCharWidth
;
87 ptmA
->tmWeight
= ptmW
->tmWeight
;
88 ptmA
->tmOverhang
= ptmW
->tmOverhang
;
89 ptmA
->tmDigitizedAspectX
= ptmW
->tmDigitizedAspectX
;
90 ptmA
->tmDigitizedAspectY
= ptmW
->tmDigitizedAspectY
;
91 ptmA
->tmFirstChar
= min(ptmW
->tmFirstChar
, 255);
92 if (ptmW
->tmCharSet
== SYMBOL_CHARSET
)
94 ptmA
->tmFirstChar
= 0x1e;
95 ptmA
->tmLastChar
= 0xff; /* win9x behaviour - we need the OS2 table data to calculate correctly */
99 ptmA
->tmFirstChar
= ptmW
->tmDefaultChar
- 1;
100 ptmA
->tmLastChar
= min(ptmW
->tmLastChar
, 0xff);
102 ptmA
->tmDefaultChar
= (CHAR
)ptmW
->tmDefaultChar
;
103 ptmA
->tmBreakChar
= (CHAR
)ptmW
->tmBreakChar
;
104 ptmA
->tmItalic
= ptmW
->tmItalic
;
105 ptmA
->tmUnderlined
= ptmW
->tmUnderlined
;
106 ptmA
->tmStruckOut
= ptmW
->tmStruckOut
;
107 ptmA
->tmPitchAndFamily
= ptmW
->tmPitchAndFamily
;
108 ptmA
->tmCharSet
= ptmW
->tmCharSet
;
111 /***********************************************************************
114 * Returns a Unicode translation of str using the charset of the
115 * currently selected font in hdc. If count is -1 then str is assumed
116 * to be '\0' terminated, otherwise it contains the number of bytes to
117 * convert. If plenW is non-NULL, on return it will point to the
118 * number of WCHARs that have been written. If pCP is non-NULL, on
119 * return it will point to the codepage used in the conversion. The
120 * caller should free the returned LPWSTR from the process heap
123 static LPWSTR
FONT_mbtowc(HDC hdc
, LPCSTR str
, INT count
, INT
*plenW
, UINT
*pCP
)
125 UINT cp
= GdiGetCodePage( hdc
);
129 if(count
== -1) count
= strlen(str
);
130 lenW
= MultiByteToWideChar(cp
, 0, str
, count
, NULL
, 0);
131 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
*sizeof(WCHAR
));
134 MultiByteToWideChar(cp
, 0, str
, count
, strW
, lenW
);
135 DPRINT("mapped %s -> %S\n", str
, strW
);
136 if(plenW
) *plenW
= lenW
;
141 static LPSTR
FONT_GetCharsByRangeA(HDC hdc
, UINT firstChar
, UINT lastChar
, PINT pByteLen
)
143 INT i
, count
= lastChar
- firstChar
+ 1;
150 switch (GdiGetCodePage(hdc
))
157 if (lastChar
> 0xffff)
159 if ((firstChar
^ lastChar
) > 0xff)
168 str
= HeapAlloc(GetProcessHeap(), 0, count
* 2 + 1);
172 for(i
= 0, c
= firstChar
; c
<= lastChar
; i
++, c
++)
175 str
[i
++] = (BYTE
)(c
>> 8);
186 NewTextMetricW2A(NEWTEXTMETRICA
*tma
, NEWTEXTMETRICW
*tmw
)
188 FONT_TextMetricWToA((TEXTMETRICW
*) tmw
, (TEXTMETRICA
*) tma
);
189 tma
->ntmFlags
= tmw
->ntmFlags
;
190 tma
->ntmSizeEM
= tmw
->ntmSizeEM
;
191 tma
->ntmCellHeight
= tmw
->ntmCellHeight
;
192 tma
->ntmAvgWidth
= tmw
->ntmAvgWidth
;
196 NewTextMetricExW2A(NEWTEXTMETRICEXA
*tma
, NEWTEXTMETRICEXW
*tmw
)
198 NewTextMetricW2A(&tma
->ntmTm
, &tmw
->ntmTm
);
199 tma
->ntmFontSig
= tmw
->ntmFontSig
;
203 IntEnumFontFamilies(HDC Dc
, LPLOGFONTW LogFont
, PVOID EnumProc
, LPARAM lParam
,
208 PFONTFAMILYINFO Info
;
211 ENUMLOGFONTEXA EnumLogFontExA
;
212 NEWTEXTMETRICEXA NewTextMetricExA
;
215 Info
= RtlAllocateHeap(GetProcessHeap(), 0,
216 INITIAL_FAMILY_COUNT
* sizeof(FONTFAMILYINFO
));
224 lfW
.lfCharSet
= DEFAULT_CHARSET
;
225 lfW
.lfPitchAndFamily
= 0;
226 lfW
.lfFaceName
[0] = 0;
230 FontFamilyCount
= NtGdiGetFontFamilyInfo(Dc
, LogFont
, Info
, INITIAL_FAMILY_COUNT
);
231 if (FontFamilyCount
< 0)
233 RtlFreeHeap(GetProcessHeap(), 0, Info
);
236 if (INITIAL_FAMILY_COUNT
< FontFamilyCount
)
238 FontFamilySize
= FontFamilyCount
;
239 RtlFreeHeap(GetProcessHeap(), 0, Info
);
240 Info
= RtlAllocateHeap(GetProcessHeap(), 0,
241 FontFamilyCount
* sizeof(FONTFAMILYINFO
));
246 FontFamilyCount
= NtGdiGetFontFamilyInfo(Dc
, LogFont
, Info
, FontFamilySize
);
247 if (FontFamilyCount
< 0 || FontFamilySize
< FontFamilyCount
)
249 RtlFreeHeap(GetProcessHeap(), 0, Info
);
254 for (i
= 0; i
< FontFamilyCount
; i
++)
258 Ret
= ((FONTENUMPROCW
) EnumProc
)(
259 (VOID
*)&Info
[i
].EnumLogFontEx
,
260 (VOID
*)&Info
[i
].NewTextMetricEx
,
261 Info
[i
].FontType
, lParam
);
265 // Could use EnumLogFontExW2A here?
266 LogFontW2A(&EnumLogFontExA
.elfLogFont
, &Info
[i
].EnumLogFontEx
.elfLogFont
);
267 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfFullName
, -1,
268 (LPSTR
)EnumLogFontExA
.elfFullName
, LF_FULLFACESIZE
, NULL
, NULL
);
269 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfStyle
, -1,
270 (LPSTR
)EnumLogFontExA
.elfStyle
, LF_FACESIZE
, NULL
, NULL
);
271 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfScript
, -1,
272 (LPSTR
)EnumLogFontExA
.elfScript
, LF_FACESIZE
, NULL
, NULL
);
273 NewTextMetricExW2A(&NewTextMetricExA
,
274 &Info
[i
].NewTextMetricEx
);
275 Ret
= ((FONTENUMPROCA
) EnumProc
)(
276 (VOID
*)&EnumLogFontExA
,
277 (VOID
*)&NewTextMetricExA
,
278 Info
[i
].FontType
, lParam
);
282 RtlFreeHeap(GetProcessHeap(), 0, Info
);
291 EnumFontFamiliesExW(HDC hdc
, LPLOGFONTW lpLogfont
, FONTENUMPROCW lpEnumFontFamExProc
,
292 LPARAM lParam
, DWORD dwFlags
)
294 return IntEnumFontFamilies(hdc
, lpLogfont
, lpEnumFontFamExProc
, lParam
, TRUE
);
302 EnumFontFamiliesW(HDC hdc
, LPCWSTR lpszFamily
, FONTENUMPROCW lpEnumFontFamProc
,
307 ZeroMemory(&LogFont
, sizeof(LOGFONTW
));
308 LogFont
.lfCharSet
= DEFAULT_CHARSET
;
309 if (NULL
!= lpszFamily
)
311 if (!*lpszFamily
) return 1;
312 lstrcpynW(LogFont
.lfFaceName
, lpszFamily
, LF_FACESIZE
);
315 return IntEnumFontFamilies(hdc
, &LogFont
, lpEnumFontFamProc
, lParam
, TRUE
);
323 EnumFontFamiliesExA (HDC hdc
, LPLOGFONTA lpLogfont
, FONTENUMPROCA lpEnumFontFamExProc
,
324 LPARAM lParam
, DWORD dwFlags
)
326 LOGFONTW LogFontW
, *pLogFontW
;
330 LogFontA2W(&LogFontW
,lpLogfont
);
331 pLogFontW
= &LogFontW
;
333 else pLogFontW
= NULL
;
335 /* no need to convert LogFontW back to lpLogFont b/c it's an [in] parameter only */
336 return IntEnumFontFamilies(hdc
, pLogFontW
, lpEnumFontFamExProc
, lParam
, FALSE
);
344 EnumFontFamiliesA(HDC hdc
, LPCSTR lpszFamily
, FONTENUMPROCA lpEnumFontFamProc
,
349 ZeroMemory(&LogFont
, sizeof(LOGFONTW
));
350 LogFont
.lfCharSet
= DEFAULT_CHARSET
;
351 if (NULL
!= lpszFamily
)
353 if (!*lpszFamily
) return 1;
354 MultiByteToWideChar(CP_THREAD_ACP
, 0, lpszFamily
, -1, LogFont
.lfFaceName
, LF_FACESIZE
);
357 return IntEnumFontFamilies(hdc
, &LogFont
, lpEnumFontFamProc
, lParam
, FALSE
);
366 GetCharacterPlacementA(
371 GCP_RESULTSA
*lpResults
,
376 GCP_RESULTSW resultsW
;
380 if ( !lpString
|| uCount
<= 0 || (nMaxExtent
< 0 && nMaxExtent
!= -1 ) )
382 SetLastError(ERROR_INVALID_PARAMETER
);
385 /* TRACE("%s, %d, %d, 0x%08x\n",
386 debugstr_an(lpString, uCount), uCount, nMaxExtent, dwFlags);
388 /* both structs are equal in size */
389 memcpy(&resultsW
, lpResults
, sizeof(resultsW
));
391 lpStringW
= FONT_mbtowc(hdc
, lpString
, uCount
, &uCountW
, &font_cp
);
392 if (lpStringW
== NULL
)
396 if(lpResults
->lpOutString
)
398 resultsW
.lpOutString
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*uCountW
);
399 if (resultsW
.lpOutString
== NULL
)
401 HeapFree(GetProcessHeap(), 0, lpStringW
);
406 ret
= GetCharacterPlacementW(hdc
, lpStringW
, uCountW
, nMaxExtent
, &resultsW
, dwFlags
);
408 lpResults
->nGlyphs
= resultsW
.nGlyphs
;
409 lpResults
->nMaxFit
= resultsW
.nMaxFit
;
411 if(lpResults
->lpOutString
)
413 WideCharToMultiByte(font_cp
, 0, resultsW
.lpOutString
, uCountW
,
414 lpResults
->lpOutString
, uCount
, NULL
, NULL
);
417 HeapFree(GetProcessHeap(), 0, lpStringW
);
418 HeapFree(GetProcessHeap(), 0, resultsW
.lpOutString
);
429 GetCharacterPlacementW(
434 GCP_RESULTSW
*lpResults
,
441 DPRINT("GetCharacterPlacementW\n");
443 if(dwFlags
&(~GCP_REORDER
)) DPRINT("flags 0x%08lx ignored\n", dwFlags
);
444 if(lpResults
->lpClass
) DPRINT("classes not implemented\n");
445 if (lpResults
->lpCaretPos
&& (dwFlags
& GCP_REORDER
))
446 DPRINT("Caret positions for complex scripts not implemented\n");
449 if(nSet
> lpResults
->nGlyphs
)
450 nSet
= lpResults
->nGlyphs
;
452 /* return number of initialized fields */
453 lpResults
->nGlyphs
= nSet
;
455 /*if((dwFlags&GCP_REORDER)==0 || !BidiAvail)
457 /* Treat the case where no special handling was requested in a fastpath way */
458 /* copy will do if the GCP_REORDER flag is not set */
459 if(lpResults
->lpOutString
)
460 lstrcpynW( lpResults
->lpOutString
, lpString
, nSet
);
462 if(lpResults
->lpGlyphs
)
463 lstrcpynW( lpResults
->lpGlyphs
, lpString
, nSet
);
465 if(lpResults
->lpOrder
)
467 for(i
= 0; i
< nSet
; i
++)
468 lpResults
->lpOrder
[i
] = i
;
472 BIDI_Reorder( lpString, uCount, dwFlags, WINE_GCPW_FORCE_LTR, lpResults->lpOutString,
473 nSet, lpResults->lpOrder );
476 /* FIXME: Will use the placement chars */
480 for (i
= 0; i
< nSet
; i
++)
482 if (GetCharWidth32W(hdc
, lpString
[i
], lpString
[i
], &c
))
483 lpResults
->lpDx
[i
]= c
;
487 if (lpResults
->lpCaretPos
&& !(dwFlags
& GCP_REORDER
))
491 lpResults
->lpCaretPos
[0] = 0;
492 for (i
= 1; i
< nSet
; i
++)
493 if (GetTextExtentPoint32W(hdc
, &(lpString
[i
- 1]), 1, &size
))
494 lpResults
->lpCaretPos
[i
] = (pos
+= size
.cx
);
497 /*if(lpResults->lpGlyphs)
498 NtGdiGetGlyphIndicesW(hdc, lpString, nSet, lpResults->lpGlyphs, 0);*/
500 if (GetTextExtentPoint32W(hdc
, lpString
, uCount
, &size
))
501 ret
= MAKELONG(size
.cx
, size
.cy
);
508 NewGetCharacterPlacementW(
513 GCP_RESULTSW
*lpResults
,
520 if ( !lpString
|| uCount
<= 0 || (nMaxExtent
< 0 && nMaxExtent
!= -1 ) )
522 SetLastError(ERROR_INVALID_PARAMETER
);
528 if ( GetTextExtentPointW(hdc
, lpString
, uCount
, &Size
) )
530 return MAKELONG(Size
.cx
, Size
.cy
);
536 if ( nSet
> lpResults
->nGlyphs
)
537 nSet
= lpResults
->nGlyphs
;
539 return NtGdiGetCharacterPlacementW( hdc
,
553 GetCharABCWidthsFloatW(HDC hdc
,
558 DPRINT("GetCharABCWidthsFloatW\n");
559 if ((!abcF
) || (FirstChar
> LastChar
))
561 SetLastError(ERROR_INVALID_PARAMETER
);
564 return NtGdiGetCharABCWidthsW( hdc
,
566 (ULONG
)(LastChar
- FirstChar
+ 1),
578 GetCharWidthFloatW(HDC hdc
,
583 DPRINT("GetCharWidthsFloatW\n");
584 if ((!pxBuffer
) || (iFirstChar
> iLastChar
))
586 SetLastError(ERROR_INVALID_PARAMETER
);
589 return NtGdiGetCharWidthW( hdc
,
591 (ULONG
)(iLastChar
- iFirstChar
+ 1),
603 GetCharWidthW(HDC hdc
,
608 DPRINT("GetCharWidthsW\n");
609 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
611 SetLastError(ERROR_INVALID_PARAMETER
);
614 return NtGdiGetCharWidthW( hdc
,
616 (ULONG
)(iLastChar
- iFirstChar
+ 1),
628 GetCharWidth32W(HDC hdc
,
633 DPRINT("GetCharWidths32W\n");
634 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
636 SetLastError(ERROR_INVALID_PARAMETER
);
639 return NtGdiGetCharWidthW( hdc
,
641 (ULONG
)(iLastChar
- iFirstChar
+ 1),
643 GCW_NOFLOAT
|GCW_WIN32
,
654 GetCharABCWidthsW(HDC hdc
,
659 DPRINT("GetCharABCWidthsW\n");
660 if ((!lpabc
) || (FirstChar
> LastChar
))
662 SetLastError(ERROR_INVALID_PARAMETER
);
665 return NtGdiGetCharABCWidthsW( hdc
,
667 (ULONG
)(LastChar
- FirstChar
+ 1),
690 DPRINT("GetCharWidthsA\n");
692 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
696 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
699 HeapFree(GetProcessHeap(), 0, str
);
703 ret
= NtGdiGetCharWidthW( hdc
,
710 HeapFree(GetProcessHeap(), 0, str
);
711 HeapFree(GetProcessHeap(), 0, wstr
);
733 DPRINT("GetCharWidths32A\n");
735 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
739 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
742 HeapFree(GetProcessHeap(), 0, str
);
746 ret
= NtGdiGetCharWidthW( hdc
,
750 GCW_NOFLOAT
|GCW_WIN32
,
753 HeapFree(GetProcessHeap(), 0, str
);
754 HeapFree(GetProcessHeap(), 0, wstr
);
776 DPRINT("GetCharWidthsFloatA\n");
778 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
782 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
785 HeapFree(GetProcessHeap(), 0, str
);
788 ret
= NtGdiGetCharWidthW( hdc
, wstr
[0], (ULONG
) count
, (PWCHAR
) wstr
, 0, (PVOID
) pxBuffer
);
790 HeapFree(GetProcessHeap(), 0, str
);
791 HeapFree(GetProcessHeap(), 0, wstr
);
813 DPRINT("GetCharABCWidthsA\n");
815 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
819 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
822 HeapFree(GetProcessHeap(), 0, str
);
826 ret
= NtGdiGetCharABCWidthsW( hdc
,
833 HeapFree(GetProcessHeap(), 0, str
);
834 HeapFree(GetProcessHeap(), 0, wstr
);
844 GetCharABCWidthsFloatA(
856 DPRINT("GetCharABCWidthsFloatA\n");
858 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
862 wstr
= FONT_mbtowc( hdc
, str
, count
+1, &wlen
, NULL
);
865 HeapFree( GetProcessHeap(), 0, str
);
868 ret
= NtGdiGetCharABCWidthsW( hdc
,wstr
[0],(ULONG
)count
, (PWCHAR
)wstr
, 0, (PVOID
)lpABCF
);
870 HeapFree( GetProcessHeap(), 0, str
);
871 HeapFree( GetProcessHeap(), 0, wstr
);
881 GetCharABCWidthsI(HDC hdc
,
887 DPRINT("GetCharABCWidthsI\n");
888 return NtGdiGetCharABCWidthsW( hdc
,
892 GCABCW_NOFLOAT
|GCABCW_INDICES
,
901 GetCharWidthI(HDC hdc
,
908 DPRINT("GetCharWidthsI\n");
909 if (!lpBuffer
|| (!pgi
&& (giFirst
== MAXUSHORT
))) // Cannot be at max.
911 SetLastError(ERROR_INVALID_PARAMETER
);
914 if (!cgi
) return TRUE
;
915 return NtGdiGetCharWidthW( hdc
,
919 GCW_INDICES
|GCW_NOFLOAT
|GCW_WIN32
,
932 DWORD Gcp
= 0, Ret
= 0;
935 Ret
= NtGdiGetTextCharsetInfo(hDc
, NULL
, 0);
936 if ((Ret
== ARABIC_CHARSET
) || (Ret
== HEBREW_CHARSET
))
937 Ret
= (GCP_KASHIDA
|GCP_DIACRITIC
|GCP_LIGATE
|GCP_GLYPHSHAPE
|GCP_REORDER
);
939 Gcp
= GetDCDWord(hDc
, GdiGetFontLanguageInfo
, GCP_ERROR
);
940 if ( Gcp
== GCP_ERROR
)
964 lpstrW
= FONT_mbtowc(hdc
, lpstr
, count
, &countW
, NULL
);
969 Ret
= NtGdiGetGlyphIndicesW(hdc
, lpstrW
, countW
, pgi
, flags
);
970 HeapFree(GetProcessHeap(), 0, lpstrW
);
993 DPRINT("GetGlyphOutlineA uChar %x\n", uChar
);
994 if (!lpgm
|| !lpmat2
) return GDI_ERROR
;
995 if(!(uFormat
& GGO_GLYPH_INDEX
))
999 if(uChar
> 0xff) /* but, 2 bytes character only */
1002 mbchs
[0] = (uChar
& 0xff00) >> 8;
1003 mbchs
[1] = (uChar
& 0xff);
1008 mbchs
[0] = (uChar
& 0xff);
1010 p
= FONT_mbtowc(hdc
, mbchs
, len
, NULL
, NULL
);
1015 ret
= NtGdiGetGlyphOutline(hdc
, c
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1016 HeapFree(GetProcessHeap(), 0, p
);
1030 LPGLYPHMETRICS lpgm
,
1036 DPRINT("GetGlyphOutlineW uChar %x\n", uChar
);
1037 if (!lpgm
|| !lpmat2
) return GDI_ERROR
;
1038 if (!lpvBuffer
) cbBuffer
= 0;
1039 return NtGdiGetGlyphOutline ( hdc
, uChar
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1058 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1067 GetOutlineTextMetricsA(
1070 LPOUTLINETEXTMETRICA lpOTM
1073 char buf
[512], *ptr
;
1075 OUTLINETEXTMETRICW
*lpOTMW
= (OUTLINETEXTMETRICW
*)buf
;
1076 OUTLINETEXTMETRICA
*output
= lpOTM
;
1079 if((ret
= GetOutlineTextMetricsW(hdc
, 0, NULL
)) == 0)
1081 if(ret
> sizeof(buf
))
1083 lpOTMW
= HeapAlloc(GetProcessHeap(), 0, ret
);
1089 GetOutlineTextMetricsW(hdc
, ret
, lpOTMW
);
1091 needed
= sizeof(OUTLINETEXTMETRICA
);
1092 if(lpOTMW
->otmpFamilyName
)
1093 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1094 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1095 NULL
, 0, NULL
, NULL
);
1096 if(lpOTMW
->otmpFaceName
)
1097 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1098 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1099 NULL
, 0, NULL
, NULL
);
1100 if(lpOTMW
->otmpStyleName
)
1101 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1102 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1103 NULL
, 0, NULL
, NULL
);
1104 if(lpOTMW
->otmpFullName
)
1105 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1106 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1107 NULL
, 0, NULL
, NULL
);
1115 DPRINT("needed = %u\n", needed
);
1118 /* Since the supplied buffer isn't big enough, we'll alloc one
1119 that is and memcpy the first cbData bytes into the lpOTM at
1121 output
= HeapAlloc(GetProcessHeap(), 0, needed
);
1128 ret
= output
->otmSize
= min(needed
, cbData
);
1129 FONT_TextMetricWToA( &lpOTMW
->otmTextMetrics
, &output
->otmTextMetrics
);
1130 output
->otmFiller
= 0;
1131 output
->otmPanoseNumber
= lpOTMW
->otmPanoseNumber
;
1132 output
->otmfsSelection
= lpOTMW
->otmfsSelection
;
1133 output
->otmfsType
= lpOTMW
->otmfsType
;
1134 output
->otmsCharSlopeRise
= lpOTMW
->otmsCharSlopeRise
;
1135 output
->otmsCharSlopeRun
= lpOTMW
->otmsCharSlopeRun
;
1136 output
->otmItalicAngle
= lpOTMW
->otmItalicAngle
;
1137 output
->otmEMSquare
= lpOTMW
->otmEMSquare
;
1138 output
->otmAscent
= lpOTMW
->otmAscent
;
1139 output
->otmDescent
= lpOTMW
->otmDescent
;
1140 output
->otmLineGap
= lpOTMW
->otmLineGap
;
1141 output
->otmsCapEmHeight
= lpOTMW
->otmsCapEmHeight
;
1142 output
->otmsXHeight
= lpOTMW
->otmsXHeight
;
1143 output
->otmrcFontBox
= lpOTMW
->otmrcFontBox
;
1144 output
->otmMacAscent
= lpOTMW
->otmMacAscent
;
1145 output
->otmMacDescent
= lpOTMW
->otmMacDescent
;
1146 output
->otmMacLineGap
= lpOTMW
->otmMacLineGap
;
1147 output
->otmusMinimumPPEM
= lpOTMW
->otmusMinimumPPEM
;
1148 output
->otmptSubscriptSize
= lpOTMW
->otmptSubscriptSize
;
1149 output
->otmptSubscriptOffset
= lpOTMW
->otmptSubscriptOffset
;
1150 output
->otmptSuperscriptSize
= lpOTMW
->otmptSuperscriptSize
;
1151 output
->otmptSuperscriptOffset
= lpOTMW
->otmptSuperscriptOffset
;
1152 output
->otmsStrikeoutSize
= lpOTMW
->otmsStrikeoutSize
;
1153 output
->otmsStrikeoutPosition
= lpOTMW
->otmsStrikeoutPosition
;
1154 output
->otmsUnderscoreSize
= lpOTMW
->otmsUnderscoreSize
;
1155 output
->otmsUnderscorePosition
= lpOTMW
->otmsUnderscorePosition
;
1158 ptr
= (char*)(output
+ 1);
1159 left
= needed
- sizeof(*output
);
1161 if(lpOTMW
->otmpFamilyName
)
1163 output
->otmpFamilyName
= (LPSTR
)(ptr
- (char*)output
);
1164 len
= WideCharToMultiByte(CP_ACP
, 0,
1165 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1166 ptr
, left
, NULL
, NULL
);
1171 output
->otmpFamilyName
= 0;
1173 if(lpOTMW
->otmpFaceName
)
1175 output
->otmpFaceName
= (LPSTR
)(ptr
- (char*)output
);
1176 len
= WideCharToMultiByte(CP_ACP
, 0,
1177 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1178 ptr
, left
, NULL
, NULL
);
1183 output
->otmpFaceName
= 0;
1185 if(lpOTMW
->otmpStyleName
)
1187 output
->otmpStyleName
= (LPSTR
)(ptr
- (char*)output
);
1188 len
= WideCharToMultiByte(CP_ACP
, 0,
1189 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1190 ptr
, left
, NULL
, NULL
);
1195 output
->otmpStyleName
= 0;
1197 if(lpOTMW
->otmpFullName
)
1199 output
->otmpFullName
= (LPSTR
)(ptr
- (char*)output
);
1200 len
= WideCharToMultiByte(CP_ACP
, 0,
1201 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1202 ptr
, left
, NULL
, NULL
);
1206 output
->otmpFullName
= 0;
1212 memcpy(lpOTM
, output
, cbData
);
1213 HeapFree(GetProcessHeap(), 0, output
);
1215 /* check if the string offsets really fit into the provided size */
1216 /* FIXME: should we check string length as well? */
1217 if ((UINT_PTR
)lpOTM
->otmpFamilyName
>= lpOTM
->otmSize
)
1218 lpOTM
->otmpFamilyName
= 0; /* doesn't fit */
1220 if ((UINT_PTR
)lpOTM
->otmpFaceName
>= lpOTM
->otmSize
)
1221 lpOTM
->otmpFaceName
= 0; /* doesn't fit */
1223 if ((UINT_PTR
)lpOTM
->otmpStyleName
>= lpOTM
->otmSize
)
1224 lpOTM
->otmpStyleName
= 0; /* doesn't fit */
1226 if ((UINT_PTR
)lpOTM
->otmpFullName
>= lpOTM
->otmSize
)
1227 lpOTM
->otmpFullName
= 0; /* doesn't fit */
1231 if(lpOTMW
!= (OUTLINETEXTMETRICW
*)buf
)
1232 HeapFree(GetProcessHeap(), 0, lpOTMW
);
1237 /* Performs a device to world transformation on the specified size (which
1238 * is in integer format).
1240 static inline INT
INTERNAL_YDSTOWS(XFORM
*xForm
, INT height
)
1244 /* Perform operation with floating point */
1245 floatHeight
= (double)height
* xForm
->eM22
;
1246 /* Round to integers */
1247 return GDI_ROUND(floatHeight
);
1250 /* scale width and height but don't mirror them */
1251 static inline INT
width_to_LP( XFORM
*xForm
, INT width
)
1253 return GDI_ROUND( (double)width
* fabs( xForm
->eM11
));
1256 static inline INT
height_to_LP( XFORM
*xForm
, INT height
)
1258 return GDI_ROUND( (double)height
* fabs( xForm
->eM22
));
1266 GetOutlineTextMetricsW(
1269 LPOUTLINETEXTMETRICW lpOTM
1272 TMDIFF Tmd
; // Should not be zero.
1273 UINT Size
, AvailableSize
= 0, StringSize
;
1275 OUTLINETEXTMETRICW
* LocalOTM
;
1279 /* Get the structure */
1280 Size
= NtGdiGetOutlineTextMetricsInternalW(hdc
, 0, NULL
, &Tmd
);
1283 if (!lpOTM
|| (cbData
< sizeof(*lpOTM
)))
1286 LocalOTM
= HeapAlloc(GetProcessHeap(), 0, Size
);
1287 LocalOTM
->otmSize
= Size
;
1288 Size
= NtGdiGetOutlineTextMetricsInternalW(hdc
, Size
, LocalOTM
, &Tmd
);
1291 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1295 if (!NtGdiGetTransform(hdc
, GdiDeviceSpaceToWorldSpace
, &DevToWorld
))
1297 DPRINT1("NtGdiGetTransform failed!\n");
1298 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1299 SetLastError(ERROR_INVALID_HANDLE
);
1303 /* Fill in DC specific data */
1304 LocalOTM
->otmTextMetrics
.tmDigitizedAspectX
= GetDeviceCaps(hdc
, LOGPIXELSX
);
1305 LocalOTM
->otmTextMetrics
.tmDigitizedAspectY
= GetDeviceCaps(hdc
, LOGPIXELSY
);
1306 LocalOTM
->otmTextMetrics
.tmHeight
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmHeight
);
1307 LocalOTM
->otmTextMetrics
.tmAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmAscent
);
1308 LocalOTM
->otmTextMetrics
.tmDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmDescent
);
1309 LocalOTM
->otmTextMetrics
.tmInternalLeading
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmInternalLeading
);
1310 LocalOTM
->otmTextMetrics
.tmExternalLeading
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmExternalLeading
);
1311 LocalOTM
->otmTextMetrics
.tmAveCharWidth
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmAveCharWidth
);
1312 LocalOTM
->otmTextMetrics
.tmMaxCharWidth
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmMaxCharWidth
);
1313 LocalOTM
->otmTextMetrics
.tmOverhang
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmOverhang
);
1314 LocalOTM
->otmAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmAscent
);
1315 LocalOTM
->otmDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmDescent
);
1316 LocalOTM
->otmLineGap
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmLineGap
));
1317 LocalOTM
->otmsCapEmHeight
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsCapEmHeight
));
1318 LocalOTM
->otmsXHeight
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsXHeight
));
1319 LocalOTM
->otmrcFontBox
.top
= height_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.top
);
1320 LocalOTM
->otmrcFontBox
.bottom
= height_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.bottom
);
1321 LocalOTM
->otmrcFontBox
.left
= width_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.left
);
1322 LocalOTM
->otmrcFontBox
.right
= width_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.right
);
1323 LocalOTM
->otmMacAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmMacAscent
);
1324 LocalOTM
->otmMacDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmMacDescent
);
1325 LocalOTM
->otmMacLineGap
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmMacLineGap
));
1326 LocalOTM
->otmptSubscriptSize
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptSize
.x
);
1327 LocalOTM
->otmptSubscriptSize
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptSize
.y
);
1328 LocalOTM
->otmptSubscriptOffset
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptOffset
.x
);
1329 LocalOTM
->otmptSubscriptOffset
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptOffset
.y
);
1330 LocalOTM
->otmptSuperscriptSize
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptSize
.x
);
1331 LocalOTM
->otmptSuperscriptSize
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptSize
.y
);
1332 LocalOTM
->otmptSuperscriptOffset
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptOffset
.x
);
1333 LocalOTM
->otmptSuperscriptOffset
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptOffset
.y
);
1334 LocalOTM
->otmsStrikeoutSize
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsStrikeoutSize
));
1335 LocalOTM
->otmsStrikeoutPosition
= height_to_LP( &DevToWorld
, LocalOTM
->otmsStrikeoutPosition
);
1336 LocalOTM
->otmsUnderscoreSize
= height_to_LP( &DevToWorld
, LocalOTM
->otmsUnderscoreSize
);
1337 LocalOTM
->otmsUnderscorePosition
= height_to_LP( &DevToWorld
, LocalOTM
->otmsUnderscorePosition
);
1339 /* Copy what we can */
1340 CopyMemory(lpOTM
, LocalOTM
, min(Size
, cbData
));
1342 lpOTM
->otmpFamilyName
= NULL
;
1343 lpOTM
->otmpFaceName
= NULL
;
1344 lpOTM
->otmpStyleName
= NULL
;
1345 lpOTM
->otmpFullName
= NULL
;
1347 Size
= sizeof(*lpOTM
);
1348 AvailableSize
= cbData
- Size
;
1349 Ptr
= (BYTE
*)lpOTM
+ sizeof(*lpOTM
);
1351 /* Fix string values up */
1352 if (LocalOTM
->otmpFamilyName
)
1354 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFamilyName
);
1355 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1356 if (AvailableSize
>= StringSize
)
1358 CopyMemory(Ptr
, Str
, StringSize
);
1359 lpOTM
->otmpFamilyName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1361 AvailableSize
-= StringSize
;
1366 if (LocalOTM
->otmpFaceName
)
1368 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFaceName
);
1369 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1370 if (AvailableSize
>= StringSize
)
1372 CopyMemory(Ptr
, Str
, StringSize
);
1373 lpOTM
->otmpFaceName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1375 AvailableSize
-= StringSize
;
1380 if (LocalOTM
->otmpStyleName
)
1382 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpStyleName
);
1383 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1384 if (AvailableSize
>= StringSize
)
1386 CopyMemory(Ptr
, Str
, StringSize
);
1387 lpOTM
->otmpStyleName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1389 AvailableSize
-= StringSize
;
1394 if (LocalOTM
->otmpFullName
)
1396 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFullName
);
1397 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1398 if (AvailableSize
>= StringSize
)
1400 CopyMemory(Ptr
, Str
, StringSize
);
1401 lpOTM
->otmpFullName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1403 AvailableSize
-= StringSize
;
1408 lpOTM
->otmSize
= Size
;
1410 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1420 GetKerningPairsW(HDC hdc
,
1422 LPKERNINGPAIR pkpDst
)
1424 if ((cPairs
!= 0) || (pkpDst
== 0))
1426 return NtGdiGetKerningPairs(hdc
,cPairs
,pkpDst
);
1430 SetLastError(ERROR_INVALID_PARAMETER
);
1440 GetKerningPairsA( HDC hDC
,
1442 LPKERNINGPAIR kern_pairA
)
1447 DWORD i
, total_kern_pairs
, kern_pairs_copied
= 0;
1448 KERNINGPAIR
*kern_pairW
;
1450 if (!cPairs
&& kern_pairA
)
1452 SetLastError(ERROR_INVALID_PARAMETER
);
1456 charset
= GetTextCharset(hDC
);
1457 if (!TranslateCharsetInfo(ULongToPtr(charset
), &csi
, TCI_SRCCHARSET
))
1459 DPRINT1("Can't find codepage for charset %d\n", charset
);
1462 /* GetCPInfo() will fail on CP_SYMBOL, and WideCharToMultiByte is supposed
1463 * to fail on an invalid character for CP_SYMBOL.
1465 cpi
.DefaultChar
[0] = 0;
1466 if (csi
.ciACP
!= CP_SYMBOL
&& !GetCPInfo(csi
.ciACP
, &cpi
))
1468 DPRINT1("Can't find codepage %u info\n", csi
.ciACP
);
1471 DPRINT("charset %d => codepage %u\n", charset
, csi
.ciACP
);
1473 total_kern_pairs
= NtGdiGetKerningPairs(hDC
, 0, NULL
);
1474 if (!total_kern_pairs
) return 0;
1476 if (!cPairs
&& !kern_pairA
) return total_kern_pairs
;
1478 kern_pairW
= HeapAlloc(GetProcessHeap(), 0, total_kern_pairs
* sizeof(*kern_pairW
));
1479 if (kern_pairW
== NULL
)
1483 GetKerningPairsW(hDC
, total_kern_pairs
, kern_pairW
);
1485 for (i
= 0; i
< total_kern_pairs
; i
++)
1489 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wFirst
, 1, &first
, 1, NULL
, NULL
))
1492 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wSecond
, 1, &second
, 1, NULL
, NULL
))
1495 if (first
== cpi
.DefaultChar
[0] || second
== cpi
.DefaultChar
[0])
1500 if (kern_pairs_copied
>= cPairs
) break;
1502 kern_pairA
->wFirst
= (BYTE
)first
;
1503 kern_pairA
->wSecond
= (BYTE
)second
;
1504 kern_pairA
->iKernAmount
= kern_pairW
[i
].iKernAmount
;
1507 kern_pairs_copied
++;
1510 HeapFree(GetProcessHeap(), 0, kern_pairW
);
1512 return kern_pairs_copied
;
1522 CreateFontIndirectExA(const ENUMLOGFONTEXDVA
*elfexd
)
1526 ENUMLOGFONTEXDVW Logfont
;
1528 EnumLogFontExW2A( (LPENUMLOGFONTEXA
) elfexd
,
1529 &Logfont
.elfEnumLogfontEx
);
1531 RtlCopyMemory( &Logfont
.elfDesignVector
,
1532 (PVOID
) &elfexd
->elfDesignVector
,
1533 sizeof(DESIGNVECTOR
));
1535 return NtGdiHfontCreate( &Logfont
, 0, 0, 0, NULL
);
1546 CreateFontIndirectExW(const ENUMLOGFONTEXDVW
*elfexd
)
1548 /* Msdn: Note, this function ignores the elfDesignVector member in
1553 return NtGdiHfontCreate((PENUMLOGFONTEXDVW
) elfexd
, 0, 0, 0, NULL
);
1564 CreateFontIndirectA(
1565 CONST LOGFONTA
*lplf
1572 LogFontA2W(&tlf
, lplf
);
1573 return CreateFontIndirectW(&tlf
);
1584 CreateFontIndirectW(
1585 CONST LOGFONTW
*lplf
1590 ENUMLOGFONTEXDVW Logfont
;
1592 RtlCopyMemory( &Logfont
.elfEnumLogfontEx
.elfLogFont
, lplf
, sizeof(LOGFONTW
));
1593 // Need something other than just cleaning memory here.
1594 // Guess? Use caller data to determine the rest.
1595 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfFullName
,
1596 sizeof(Logfont
.elfEnumLogfontEx
.elfFullName
));
1597 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfStyle
,
1598 sizeof(Logfont
.elfEnumLogfontEx
.elfStyle
));
1599 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfScript
,
1600 sizeof(Logfont
.elfEnumLogfontEx
.elfScript
));
1602 Logfont
.elfDesignVector
.dvNumAxes
= 0; // No more than MM_MAX_NUMAXES
1604 RtlZeroMemory( &Logfont
.elfDesignVector
, sizeof(DESIGNVECTOR
));
1606 return CreateFontIndirectExW(&Logfont
);
1627 DWORD fdwOutputPrecision
,
1628 DWORD fdwClipPrecision
,
1630 DWORD fdwPitchAndFamily
,
1634 ANSI_STRING StringA
;
1635 UNICODE_STRING StringU
;
1638 RtlInitAnsiString(&StringA
, (LPSTR
)lpszFace
);
1639 RtlAnsiStringToUnicodeString(&StringU
, &StringA
, TRUE
);
1641 ret
= CreateFontW(nHeight
,
1656 RtlFreeUnicodeString(&StringU
);
1677 DWORD fdwOutputPrecision
,
1678 DWORD fdwClipPrecision
,
1680 DWORD fdwPitchAndFamily
,
1686 logfont
.lfHeight
= nHeight
;
1687 logfont
.lfWidth
= nWidth
;
1688 logfont
.lfEscapement
= nEscapement
;
1689 logfont
.lfOrientation
= nOrientation
;
1690 logfont
.lfWeight
= nWeight
;
1691 logfont
.lfItalic
= (BYTE
)fnItalic
;
1692 logfont
.lfUnderline
= (BYTE
)fdwUnderline
;
1693 logfont
.lfStrikeOut
= (BYTE
)fdwStrikeOut
;
1694 logfont
.lfCharSet
= (BYTE
)fdwCharSet
;
1695 logfont
.lfOutPrecision
= (BYTE
)fdwOutputPrecision
;
1696 logfont
.lfClipPrecision
= (BYTE
)fdwClipPrecision
;
1697 logfont
.lfQuality
= (BYTE
)fdwQuality
;
1698 logfont
.lfPitchAndFamily
= (BYTE
)fdwPitchAndFamily
;
1700 if (NULL
!= lpszFace
)
1702 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
1703 wcsncpy((wchar_t *)logfont
.lfFaceName
, lpszFace
, Size
- 1);
1704 /* Be 101% sure to have '\0' at end of string */
1705 logfont
.lfFaceName
[Size
- 1] = '\0';
1709 logfont
.lfFaceName
[0] = L
'\0';
1712 return CreateFontIndirectW(&logfont
);
1721 CreateScalableFontResourceA(
1724 LPCSTR lpszFontFile
,
1725 LPCSTR lpszCurrentPath
1737 AddFontResourceExW ( LPCWSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1739 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1741 SetLastError( ERROR_INVALID_PARAMETER
);
1745 return GdiAddFontResourceW(lpszFilename
, fl
,0);
1754 AddFontResourceExA ( LPCSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1760 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1762 SetLastError( ERROR_INVALID_PARAMETER
);
1766 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1767 if ( !NT_SUCCESS (Status
) )
1769 SetLastError (RtlNtStatusToDosError(Status
));
1773 rc
= GdiAddFontResourceW ( FilenameW
, fl
, 0 );
1774 HEAP_free ( FilenameW
);
1784 AddFontResourceA ( LPCSTR lpszFilename
)
1790 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1791 if ( !NT_SUCCESS (Status
) )
1793 SetLastError (RtlNtStatusToDosError(Status
));
1797 rc
= GdiAddFontResourceW ( FilenameW
, 0, 0);
1799 HEAP_free ( FilenameW
);
1810 AddFontResourceW ( LPCWSTR lpszFilename
)
1812 return GdiAddFontResourceW ( lpszFilename
, 0, 0 );
1821 RemoveFontResourceW(LPCWSTR lpFileName
)
1823 return RemoveFontResourceExW(lpFileName
,0,0);
1832 RemoveFontResourceA(LPCSTR lpFileName
)
1834 return RemoveFontResourceExA(lpFileName
,0,0);
1842 RemoveFontResourceExA(LPCSTR lpFileName
,
1850 /* FIXME the flags */
1852 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1854 Status
= HEAP_strdupA2W ( &lpFileNameW
, lpFileName
);
1855 if (!NT_SUCCESS (Status
))
1856 SetLastError (RtlNtStatusToDosError(Status
));
1860 HEAP_free ( lpFileNameW
);
1871 RemoveFontResourceExW(LPCWSTR lpFileName
,
1875 /* FIXME the flags */
1877 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1882 /***********************************************************************
1883 * GdiGetCharDimensions
1885 * Gets the average width of the characters in the English alphabet.
1888 * hdc [I] Handle to the device context to measure on.
1889 * lptm [O] Pointer to memory to store the text metrics into.
1890 * height [O] On exit, the maximum height of characters in the English alphabet.
1893 * The average width of characters in the English alphabet.
1896 * This function is used by the dialog manager to get the size of a dialog
1897 * unit. It should also be used by other pieces of code that need to know
1898 * the size of a dialog unit in logical units without having access to the
1899 * window handle of the dialog.
1900 * Windows caches the font metrics from this function, but we don't and
1901 * there doesn't appear to be an immediate advantage to do so.
1904 * GetTextExtentPointW, GetTextMetricsW, MapDialogRect.
1906 * Despite most of MSDN insisting that the horizontal base unit is
1907 * tmAveCharWidth it isn't. Knowledge base article Q145994
1908 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
1909 * says that we should take the average of the 52 English upper and lower
1917 GdiGetCharDimensions(HDC hdc
, LPTEXTMETRICW lptm
, LONG
*height
)
1921 static const WCHAR alphabet
[] =
1923 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
1924 'r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H',
1925 'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',0
1928 if(!GetTextMetricsW(hdc
, &tm
)) return 0;
1930 if(!GetTextExtentPointW(hdc
, alphabet
, 52, &sz
)) return 0;
1932 if (lptm
) *lptm
= tm
;
1933 if (height
) *height
= tm
.tmHeight
;
1935 return (sz
.cx
/ 26 + 1) / 2;
1938 /*************************************************************************
1939 * TranslateCharsetInfo [GDI32.@]
1941 * Fills a CHARSETINFO structure for a character set, code page, or
1942 * font. This allows making the correspondance between different labelings
1943 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1944 * of the same encoding.
1946 * Only one codepage will be set in lpCs->fs. If TCI_SRCFONTSIG is used,
1947 * only one codepage should be set in *lpSrc.
1950 * TRUE on success, FALSE on failure.
1958 TranslateCharsetInfo(
1959 LPDWORD lpSrc
, /* [in]
1960 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1961 if flags == TCI_SRCCHARSET: a character set value
1962 if flags == TCI_SRCCODEPAGE: a code page value
1964 LPCHARSETINFO lpCs
, /* [out] structure to receive charset information */
1965 DWORD flags
/* [in] determines interpretation of lpSrc */)
1970 case TCI_SRCFONTSIG
:
1971 while (index
< MAXTCIINDEX
&& !(*lpSrc
>>index
& 0x0001)) index
++;
1973 case TCI_SRCCODEPAGE
:
1974 while (index
< MAXTCIINDEX
&& PtrToUlong(lpSrc
) != FONT_tci
[index
].ciACP
) index
++;
1976 case TCI_SRCCHARSET
:
1977 while (index
< MAXTCIINDEX
&& PtrToUlong(lpSrc
) != FONT_tci
[index
].ciCharset
) index
++;
1981 LCID lCid
= (LCID
)PtrToUlong(lpSrc
);
1982 LOCALESIGNATURE LocSig
;
1983 INT Ret
= GetLocaleInfoW(lCid
, LOCALE_FONTSIGNATURE
, (LPWSTR
)&LocSig
, 0);
1984 if ( GetLocaleInfoW(lCid
, LOCALE_FONTSIGNATURE
, (LPWSTR
)&LocSig
, Ret
))
1986 while (index
< MAXTCIINDEX
&& !(LocSig
.lsCsbDefault
[0]>>index
& 0x0001)) index
++;
1991 GdiSetLastError(ERROR_INVALID_PARAMETER
);
1994 if (index
>= MAXTCIINDEX
|| FONT_tci
[index
].ciCharset
== DEFAULT_CHARSET
) return FALSE
;
1995 DPRINT("Index %d Charset %u CodePage %u FontSig %lu\n",
1996 index
,FONT_tci
[index
].ciCharset
,FONT_tci
[index
].ciACP
,FONT_tci
[index
].fs
.fsCsb
[0]);
1997 memcpy(lpCs
, &FONT_tci
[index
], sizeof(CHARSETINFO
));
2012 DWORD Ret
= GDI_ERROR
;
2015 if (GDI_HANDLE_GET_TYPE(hDC
) != GDI_OBJECT_TYPE_DC
)
2017 if (GDI_HANDLE_GET_TYPE(hDC
) == GDI_OBJECT_TYPE_METADC
)
2018 return MFDRV_SetMapperFlags( hDC
, flags
);
2021 PLDC pLDC
= Dc_Attr
->pvLDC
;
2024 SetLastError(ERROR_INVALID_HANDLE
);
2027 if (pLDC
->iType
== LDC_EMFLDC
)
2029 return EMFDRV_SetMapperFlags( hDC
, flags
);
2034 if (!GdiGetHandleUserData((HGDIOBJ
) hDC
, GDI_OBJECT_TYPE_DC
, (PVOID
) &Dc_Attr
)) return GDI_ERROR
;
2036 if (NtCurrentTeb()->GdiTebBatch
.HDC
== hDC
)
2038 if (Dc_Attr
->ulDirty_
& DC_FONTTEXT_DIRTY
)
2041 Dc_Attr
->ulDirty_
&= ~(DC_MODE_DIRTY
|DC_FONTTEXT_DIRTY
);
2046 SetLastError(ERROR_INVALID_PARAMETER
);
2049 Ret
= Dc_Attr
->flFontMapper
;
2050 Dc_Attr
->flFontMapper
= flags
;
2064 FONTENUMPROCW FontFunc
,
2069 return NtGdiEnumFonts ( hDC
, lpFaceName
, FontFunc
, lParam
);
2071 return EnumFontFamiliesW( hDC
, lpFaceName
, FontFunc
, lParam
);
2083 FONTENUMPROCA FontFunc
,
2092 Status
= HEAP_strdupA2W ( &lpFaceNameW
, lpFaceName
);
2093 if (!NT_SUCCESS (Status
))
2094 SetLastError (RtlNtStatusToDosError(Status
));
2097 rc
= NtGdiEnumFonts ( hDC
, lpFaceNameW
, FontFunc
, lParam
);
2099 HEAP_free ( lpFaceNameW
);
2103 return EnumFontFamiliesA( hDC
, lpFaceName
, FontFunc
, lParam
);
2107 #define EfdFontFamilies 3
2111 NewEnumFontFamiliesExW(
2113 LPLOGFONTW lpLogfont
,
2114 FONTENUMPROCW lpEnumFontFamExProcW
,
2118 ULONG_PTR idEnum
, cbDataSize
, cbRetSize
;
2119 PENUMFONTDATAW pEfdw
;
2124 /* Open enumeration handle and find out how much memory we need */
2125 idEnum
= NtGdiEnumFontOpen(hDC
,
2129 (lpLogfont
&& lpLogfont
->lfFaceName
[0])? lpLogfont
->lfFaceName
: NULL
,
2130 lpLogfont
? lpLogfont
->lfCharSet
: DEFAULT_CHARSET
,
2136 if (cbDataSize
== 0)
2138 NtGdiEnumFontClose(idEnum
);
2142 /* Allocate memory */
2143 pBuffer
= HeapAlloc(GetProcessHeap(), 0, cbDataSize
);
2144 if (pBuffer
== NULL
)
2146 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2147 NtGdiEnumFontClose(idEnum
);
2151 /* Do the enumeration */
2152 if (!NtGdiEnumFontChunk(hDC
, idEnum
, cbDataSize
, &cbRetSize
, (PVOID
)pBuffer
))
2154 HeapFree(GetProcessHeap(), 0, pBuffer
);
2155 NtGdiEnumFontClose(idEnum
);
2159 /* Get start and end address */
2160 pEfdw
= (PENUMFONTDATAW
)pBuffer
;
2161 pMax
= pBuffer
+ cbDataSize
;
2163 /* Iterate through the structures */
2164 while ((PBYTE
)pEfdw
< pMax
&& ret
)
2166 PNTMW_INTERNAL pNtmwi
= (PNTMW_INTERNAL
)((ULONG_PTR
)pEfdw
+ pEfdw
->ulNtmwiOffset
);
2168 ret
= lpEnumFontFamExProcW((VOID
*)&pEfdw
->elfexdv
.elfEnumLogfontEx
,
2169 (VOID
*)&pNtmwi
->ntmw
,
2173 pEfdw
= (PENUMFONTDATAW
)((ULONG_PTR
)pEfdw
+ pEfdw
->cbSize
);
2176 /* Release the memory and close handle */
2177 HeapFree(GetProcessHeap(), 0, pBuffer
);
2178 NtGdiEnumFontClose(idEnum
);
2188 GdiAddFontResourceW(
2189 LPCWSTR lpszFilename
,
2193 return NtGdiAddFontResourceW((PWSTR
)lpszFilename
, 0, 0, fl
, 0, pdv
);
2201 AddFontMemResourceEx(
2208 if ( pbFont
&& cbFont
&& pcFonts
)
2210 return NtGdiAddFontMemResourceEx(pbFont
, cbFont
, NULL
, 0, pcFonts
);
2212 SetLastError(ERROR_INVALID_PARAMETER
);
2221 RemoveFontMemResourceEx(HANDLE fh
)
2225 return NtGdiRemoveFontMemResourceEx(fh
);
2227 SetLastError(ERROR_INVALID_PARAMETER
);
2237 AddFontResourceTracking(
2243 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2252 RemoveFontResourceTracking(LPCSTR lpString
,int unknown
)
2255 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2261 CreateScalableFontResourceW(
2263 LPCWSTR lpszFontRes
,
2264 LPCWSTR lpszFontFile
,
2265 LPCWSTR lpszCurrentPath
2272 /* fHidden=1 - only visible for the calling app, read-only, not
2273 * enumerated with EnumFonts/EnumFontFamilies
2274 * lpszCurrentPath can be NULL
2277 /* If the output file already exists, return the ERROR_FILE_EXISTS error as specified in MSDN */
2278 if ((f
= CreateFileW(lpszFontRes
, 0, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, 0)) != INVALID_HANDLE_VALUE
)
2281 SetLastError(ERROR_FILE_EXISTS
);
2284 return FALSE
; /* create failed */
2292 bInitSystemAndFontsDirectoriesW(LPWSTR
*SystemDir
,LPWSTR
*FontsDir
)
2295 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2304 EudcLoadLinkW(LPCWSTR pBaseFaceName
,LPCWSTR pEudcFontPath
,INT iPriority
,INT iFontLinkType
)
2307 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2316 EudcUnloadLinkW(LPCWSTR pBaseFaceName
,LPCWSTR pEudcFontPath
)
2319 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2328 GetEUDCTimeStamp(VOID
)
2330 return NtGdiGetEudcTimeStampEx(NULL
,0,TRUE
);
2338 GetEUDCTimeStampExW(LPWSTR lpBaseFaceName
)
2342 if (!lpBaseFaceName
)
2344 retValue
= NtGdiGetEudcTimeStampEx(NULL
,0,FALSE
);
2348 retValue
= NtGdiGetEudcTimeStampEx(lpBaseFaceName
, wcslen(lpBaseFaceName
), FALSE
);
2359 GetFontAssocStatus(HDC hdc
)
2365 retValue
= NtGdiQueryFontAssocInfo(hdc
);
2376 QueryFontAssocStatus(VOID
)
2379 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2388 UnloadNetworkFonts(DWORD unknown
)
2391 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2400 GetFontData(HDC hdc
,
2410 return NtGdiGetFontData(hdc
, dwTable
, dwOffset
, lpvBuffer
, cbData
);
2415 cGetTTFFromFOT(DWORD x1
,DWORD x2
,DWORD x3
, DWORD x4
, DWORD x5
, DWORD x6
, DWORD x7
)
2418 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);