//font 字体 import gdi; import gdip.core; namespace gdip; class font { ctor( hdcIn,logfont,... ){ var err; if( hdcIn[["pFamily"]] ){ this.__family = hdcIn;//gc; var pFamily,emSize,style,unit = hdcIn[["pFamily"]],logfont,... ; if( style === null ) style = 0/*_GdipFontStyleRegular*/; if( unit === null ) unit = 2/*_GdipUnitPixel*/; err,this.pFont = gdip.CreateFont(pFamily,..math.abs(emSize),style,unit) } elseif(type(hdcIn)=="string"){ var name,emSize,style,unit = hdcIn,logfont,... ; if( style === null ) style = 0/*_GdipFontStyleRegular*/; if( unit === null ) unit = 2/*_GdipUnitPixel*/; if(name === null || name === "Tahoma" ) { name = _WINXP ? "MS Shell Dlg" : "Segoe UI"; } var e,f = gdip.CreateFontFamilyFromName(name) ; if( e ) return null,gdip.errMsg[e]; err,this.pFont = gdip.CreateFont(f,..math.abs(emSize),style,unit) this.pFamily___ = f; } else { hdc = hdcIn : ::GetDC(0); if( !logfont ){ err,this.pFont = gdip.CreateFontFromDC(hdc); } else { logfont.stripPoint(hdcIn); var privateFamily = ..fonts[["_privateGdipFamilies"]][[logfont.name]]; if(privateFamily[["pFamily"]]){ var style = logfont.weight > 600 ? 1/*_FontStyleBold*/ : 0/*_FontStyleRegular*/; if( logfont.underline ) style = style | 4/*_FontStyleUnderline*/ if( logfont.strike ) style = style | 8/*_FontStyleStrikeout*/ if( logfont.italic ) style = style | 2/*_FontStyleItalic*/; err,this.pFont = gdip.CreateFont(privateFamily[["pFamily"]],..math.abs(logfont.h),style,2/*_GdipUnitPixel*/ ); } else { err,this.pFont = gdip.CreateFontFromLogfont(hdc,logfont); } } if(!hdcIn) ::ReleaseDC(0,hdc); } if( err ) return null,gdip.errMsg[err]; if(!this.pFont) error("创建字体参数错误",2) ; ..table.gc(this,"delete"); } @_metaProperty } namespace font { self.gdip = ..gdip; var gdip = gdip; _metaProperty = ..util.metaProperty( getStyle = function( ){ return gdip.assert( gdip.GetFontStyle(owner[["pFont"]],0) ); } getSize = function( ){ return gdip.assert( gdip.GetFontSize(owner[["pFont"]],0) ); } getUnit = function( ){ return gdip.assert( gdip.GetFontUnit(owner[["pFont"]],0) ); } getHeight = function(graphics){ return gdip.assert( gdip.GetFontHeight(owner[["pFont"]],graphics,0 ) ); } getLogFont = function(graphics){ return gdip.assert( gdip.GetLogFont(owner[["pFont"]],graphics,::LOGFONT() ) ); } clone = function(){ return ..table.gc( { pFont = gdip.assert( gdip.CloneFont(owner[["pFont"]] ) ); @_metaProperty },"delete" ); } delete = function(){ if( owner[["pFont"]] ){ gdip.DeleteFont(owner[["pFont"]]) if(owner[["pFamily___"]]) { ::Gdiplus.GdipDeleteFontFamily(owner[["pFamily___"]]); pFamily___ = null; } owner[["pFont"]] = null;//让其他的函数都用不了 } } _type = "gdip.font"; _topointer = function(){ return owner[["pFont"]]; } ) } var $ = _dll; /*intellisense(gdip)*/ CreateFontFromDC = $.api("GdipCreateFontFromDC","int(POINTER hDc,pointer& createdfont)") CreateFontFromLogfont = $.api("GdipCreateFontFromLogfont","int(POINTER hDc,struct logfont,pointer& createdfont)") GetLogFont = $.api("GdipGetLogFont","int(POINTER curFont,pointer Graphics,struct& logfont)") CloneFont = $.api("GdipCloneFont","int(POINTER curFont,pointer& cloneFont)") GetFamily = $.api("GdipGetFamily","int(POINTER curFont,pointer& family)") GetFontStyle = $.api("GdipGetFontStyle","int(POINTER curFont,int& style)") GetFontSize = $.api("GdipGetFontSize","int(POINTER curFont,float& size)") GetFontUnit = $.api("GdipGetFontUnit","int(POINTER curFont,int& unit)") GetFontHeight = $.api("GdipGetFontHeight","int(POINTER curFont,pointer Graphics,float& Height)") /*end intellisense*/ self.CreateFont = $.api("GdipCreateFont","int(PTR family,float emSize,int style,int unit,pointer& createdfont)") self.DeleteFont = $.api("GdipDeleteFont","int(POINTER curFont)") CreateFontFamilyFromName := $.api("GdipCreateFontFamilyFromName","int(ustring name,ptr fontColl,pointer& fontFamily)") /**intellisense() gdip.font = 指定字形风格(例如常规、粗体)的字体(font)对象 gdip.font( = 创建字体 gdip.font(.(fontFamily,emSize,style,unit) = 创建字体,\n参数@fontFamily 指定 gdip.family 对象。\n参数@emSize指定大小,\n可选参数@style 使用 _GdipFontStyle 前缀的常量指定字形样式,默认为 _GdipFontStyleRegular。\n可选参数@unit 指定单位,默认值为_GdipUnitPixel gdip.font(.(fontName,emSize,style,unit) = 创建字体,\n参数@fontName 指定 字体名称。\n参数@emSize指定大小,\n可选参数@style 使用 _GdipFontStyle 前缀的常量指定字形样式,默认为 _GdipFontStyleRegular。\n可选参数@unit 指定单位,默认值为_GdipUnitPixel gdip.font(.(hdc) = hdc为空则取屏幕DC gdip.font(.(hdc,LOGFONT字体) = 使用LOGFONT字体创建GDI+字体对象\n可自动支持fonts命名空间下已导入的自带字体\n参数hdc为空则取屏幕DC gdip.font() = !gdipfont. !gdipfont.getStyle() = 样式\n数值 !gdipfont.getSize() = 字体大小\n数值 !gdipfont.getUnit() = 单位\n数值 !gdipfont.getHeight(.(graphics) = 显示高度\n数值 !gdipfont.getLogFont(.(graphics) = 返回LOGFONT字体对象 !gdipfont.clone() = 复制字体\n!gdipfont. !gdipfont.delete() = 删除字体 end intellisense**/