CreateFont
TheCreateFontfunctioncreatesalogicalfontwiththespecifiedcharacteristics.Thelogicalfontcansubsequentlybeselectedasthefontforanydevice.
HFONTCreateFont(
intnHeight,//heightoffont
intnWidth,//averagecharacterwidth
intnEscapement,//angleofescapement
intnOrientation,//base-lineorientationangle
intfnWeight,//fontweight
DWORDfdwItalic,//italicattributeoption
DWORDfdwUnderline,//underlineattributeoption
DWORDfdwStrikeOut,//strikeoutattributeoption
DWORDfdwCharSet,//charactersetidentifier
DWORDfdwOutputPrecision,//outputprecision
DWORDfdwClipPrecision,//clippingprecision
DWORDfdwQuality,//outputquality
DWORDfdwPitchAndFamily,//pitchandfamily
LPCTSTRlpszFace//typefacename
);
Parameters
nHeight
[in]Specifiestheheight,inlogicalunits,ofthefont'scharactercellorcharacter.Thecharacterheightvalue(alsoknownastheemheight)isthecharactercellheightvalueminustheinternal-leadingvalue.ThefontmapperinterpretsthevaluespecifiedinnHeightinthefollowingmanner.
nWidth
[in]Specifiestheaveragewidth,inlogicalunits,ofcharactersintherequestedfont.Ifthisvalueiszero,thefontmapperchoosesaclosestmatchvalue.Theclosestmatchvalueisdeterminedbycomparingtheabsolutevaluesofthedifferencebetweenthecurrentdevice'saspectratioandthedigitizedaspectratioofavailablefonts.
nEscapement
[in]Specifiestheangle,intenthsofdegrees,betweentheescapementvectorandthex-axisofthedevice.Theescapementvectorisparalleltothebaselineofarowoftext.
WindowsNT/2000/XP:WhenthegraphicsmodeissettoGM_ADVANCED,youcanspecifytheescapementangleofthestringindependentlyoftheorientationangleofthestring'scharacters.
WhenthegraphicsmodeissettoGM_COMPATIBLE,nEscapementspecifiesboththeescapementandorientation.YoushouldsetnEscapementandnOrientationtothesamevalue.
Windows95/98/Me:ThenEscapementparameterspecifiesboththeescapementandorientation.YoushouldsetnEscapementandnOrientationtothesamevalue.
nOrientation
[in]Specifiestheangle,intenthsofdegrees,betweeneachcharacter'sbaselineandthex-axisofthedevice.
fnWeight
[in]Specifiestheweightofthefontintherange0through1000.Forexample,400isnormaland700isbold.Ifthisvalueiszero,adefaultweightisused.
Thefollowingvaluesaredefinedforconvenience.
fdwItalic
[in]SpecifiesanitalicfontifsettoTRUE.
fdwUnderline
[in]SpecifiesanunderlinedfontifsettoTRUE.
fdwStrikeOut
[in]SpecifiesastrikeoutfontifsettoTRUE.
fdwCharSet
[in]Specifiesthecharacterset.Thefollowingvaluesarepredefined:
ANSI_CHARSET
BALTIC_CHARSET
CHINESEBIG5_CHARSET
DEFAULT_CHARSET
EASTEUROPE_CHARSET
GB2312_CHARSET
GREEK_CHARSET
HANGUL_CHARSET
MAC_CHARSET
OEM_CHARSET
RUSSIAN_CHARSET
SHIFTJIS_CHARSET
SYMBOL_CHARSET
TURKISH_CHARSET
VIETNAMESE_CHARSET
KoreanlanguageeditionofWindows:
JOHAB_CHARSET
MiddleEastlanguageeditionofWindows:
ARABIC_CHARSET
HEBREW_CHARSET
ThailanguageeditionofWindows:
THAI_CHARSET
TheOEM_CHARSETvaluespecifiesacharactersetthatisoperating-systemdependent.
Windows95/98/Me:YoucanusetheDEFAULT_CHARSETvaluetoallowthenameandsizeofafonttofullydescribethelogicalfont.Ifthespecifiedfontnamedoesnotexist,afontfromanycharactersetcanbesubstitutedforthespecifiedfont,soyoushoulduseDEFAULT_CHARSETsparinglytoavoidunexpectedresults.
WindowsNT/2000/XP:DEFAULT_CHARSETissettoavaluebasedonthecurrentsystemlocale.Forexample,whenthesystemlocaleisEnglish(UnitedStates),itissetasANSI_CHARSET.
Fontswithothercharactersetsmayexistintheoperatingsystem.Ifanapplicationusesafontwithanunknowncharacterset,itshouldnotattempttotranslateorinterpretstringsthatarerenderedwiththatfont.
Toensureconsistentresultswhencreatingafont,donotspecifyOEM_CHARSETorDEFAULT_CHARSET.IfyouspecifyatypefacenameinthelpszFaceparameter,makesurethatthefdwCharSetvaluematchesthecharactersetofthetypefacespecifiedinlpszFace.
fdwOutputPrecision
[in]Specifiestheoutputprecision.Theoutputprecisiondefineshowcloselytheoutputmustmatchtherequestedfont'sheight,width,characterorientation,escapement,pitch,andfonttype.Itcanbeoneofthefollowingvalues.
ApplicationscanusetheOUT_DEVICE_PRECIS,OUT_RASTER_PRECIS,OUT_TT_PRECIS,andOUT_PS_ONLY_PRECISvaluestocontrolhowthefontmapperchoosesafontwhentheoperatingsystemcontainsmorethanonefontwithaspecifiedname.Forexample,ifanoperatingsystemcontainsafontnamedSymbolinrasterandTrueTypeform,specifyingOUT_TT_PRECISforcesthefontmappertochoosetheTrueTypeversion.SpecifyingOUT_TT_ONLY_PRECISforcesthefontmappertochooseaTrueTypefont,evenifitmustsubstituteaTrueTypefontofanothername.
fdwClipPrecision
[in]Specifiestheclippingprecision.Theclippingprecisiondefineshowtoclipcharactersthatarepartiallyoutsidetheclippingregion.Itcanbeoneormoreofthefollowingvalues.
fdwQuality
[in]Specifiestheoutputquality.TheoutputqualitydefineshowcarefullyGDImustattempttomatchthelogical-fontattributestothoseofanactualphysicalfont.Itcanbeoneofthefollowingvalues.
tla_shell
IftheoutputqualityisDEFAULT_QUALITY,DRAFT_QUALITY,orPROOF_QUALITY,thenthefontisantialiasediftheSPI_GETFONTSMOOTHINGsystemparameterisTRUE.UserscancontrolthissystemparameterfromtheControlPanel.(TheprecisewordingofthesettingintheControlpaneldependsontheversionofWindows,butitwillbewordstotheeffectof"Smoothedgesofscreenfonts".)
fdwPitchAndFamily
[in]Specifiesthepitchandfamilyofthefont.Thetwolow-orderbitsspecifythepitchofthefontandcanbeoneofthefollowingvalues:
DEFAULT_PITCH
FIXED_PITCH
VARIABLE_PITCH
Thefourhigh-orderbitsspecifythefontfamilyandcanbeoneofthefollowingvalues.
AnapplicationcanspecifyavalueforthefdwPitchAndFamilyparameterbyusingtheBooleanORoperatortojoinapitchconstantwithafamilyconstant.
Fontfamiliesdescribethelookofafontinageneralway.Theyareintendedforspecifyingfontswhentheexacttypefacerequestedisnotavailable.
lpszFace
[in]Pointertoanull-terminatedstringthatspecifiesthetypefacenameofthefont.Thelengthofthisstringmustnotexceed32characters,includingtheterminatingnullcharacter.TheEnumFontFamiliesfunctioncanbeusedtoenumeratethetypefacenamesofallcurrentlyavailablefonts.Formoreinformation,seetheRemarks.
IflpszFaceisNULLoremptystring,GDIusesthefirstfontthatmatchestheotherspecifiedattributes.
ReturnValues
Ifthefunctionsucceeds,thereturnvalueisahandletoalogicalfont.
Ifthefunctionfails,thereturnvalueisNULL.
WindowsNT/2000/XP:Togetextendederrorinformation,callGetLastError.
Remarks
Whenyounolongerneedthefont,calltheDeleteObjectfunctiontodeleteit.
TohelpprotectthecopyrightsofvendorswhoprovidefontsforWindows,applicationsshouldalwaysreporttheexactnameofaselectedfont.Becauseavailablefontscanvaryfromsystemtosystem,donotassumethattheselectedfontisalwaysthesameastherequestedfont.Forexample,ifyourequestafontnamedPalatino,butnosuchfontisavailableonthesystem,thefontmapperwillsubstituteafontthathassimilarattributesbutadifferentname.Alwaysreportthenameoftheselectedfonttotheuser.
TogettheappropriatefontondifferentlanguageversionsoftheOS,callEnumFontFamiliesExwiththedesiredfontcharacteristicsintheLOGFONTstructure,thenretrievetheappropriatetypefacenameandcreatethefontusingCreateFontorCreateFontIndirect.
Windows95/98/Me,WindowsNT4.0:ThefontsformanyEastAsianlanguageshavetwotypefacenames:anEnglishnameandalocalizedname.CreateFont,CreateFontIndirectandCreateFontIndirectExtakethelocalizedtypefacenameonasystemlocalethatmatchesthelanguage,buttheytaketheEnglishtypefacenameonallothersystemlocales.Thebestmethodistotryonenameand,onfailure,trytheother.NotethatEnumFonts,EnumFontFamilies,andEnumFontFamiliesExreturntheEnglishtypefacenameifthesystemlocaledoesnotmatchthelanguageofthefont.
Windows2000/XP:ThefontmapperforCreateFont,CreateFontIndirect,andCreateFontIndirectExrecognizesboththeEnglishandthelocalizedtypefacename,regardlessoflocale.
WindowsXP:ThefollowingsituationsdonotsupportClearTypeantialiasing:
Textrenderedonaprinter.
Adisplaysetfor256colorsorless.
Textrenderedtoaterminalserverclient.
ThefontisnotaTrueTypefontoranOpenTypefontwithTrueTypeoutlines.Forexample,thefollowingdonotsupportClearTypeantialiasing:Type1fonts,PostscriptOpenTypefontswithoutTrueTypeoutlines,bitmapfonts,vectorfonts,anddevicefonts.
Thefonthastunedembeddedbitmaps,onlyforthefontsizesthatcontaintheembeddedbitmaps.Forexample,thisoccurscommonlyinEastAsianfonts.
Windows95/98/Me:CreateFontWissupportedbytheMicrosoftLayerforUnicode.Tousethis,youmustaddcertainfilestoyourapplication,asoutlinedinMicrosoftLayerforUnicodeonWindows95/98/MeSystems. |