导航:  GdiPlus Classes > GdiPlus Classes > CGpFont Class > Font Object >

GetLogFont

上一页返回章节概述下一页

描述

 

采用LOGFONT结构得到这Font对象的属性.

 

C++ Syacntax

 

Status GetLogFontA(

[in]   const Graphics *g,

[out]  LOGFONTA *logfontA

) const;

Status GetLogFontW(

[in]   const Graphics *g,

[out]  LOGFONTW *logfontA

) const;

 

FreeBASIC 语法

 

FUNCTION GetLogFontA ( _

   BYVAL pGraphics AS CGpGraphics PTR, _

   BYVAL pLogFont AS LOGFONTA PTR _

) AS GpStatus

 

FUNCTION GetLogFontW ( _

   BYVAL pGraphics AS CGpGraphics PTR, _

   BYVAL pLogFont AS LOGFONTW PTR _

) AS GpStatus

 

参数

 

pGraphics

 

[in]指向Graphics对象包含显示设备的属性.

 

pLogFont

 

[out]指针指向一个结构变量,LOGFONT接收字体属性.

 

返回值

 

如果该方法成功,则返回Ok,这是对Status枚举元素.

如果这个方法失败,它返回一个枚举的其他元素的Status.

 

引用文件

 

CGpFont.inc (include CGdiPlus.inc)

 

示例

 

' ========================================================================================

' The following example creates a Font object, gets the font attributes from the Font object,

' and uses these attributes (contained in the LOGFONTA structure) to create a second Font

' object. The second Font object is then used to draw text.

' ========================================================================================

SUB Example_GetLogFontA (BYVAL hdc AS HDC)

 

  ' // Create a graphics object from the window device context

  DIM graphics AS CGpGraphics = hdc

  ' // Get the DPI scaling ratio

  DIM rxRatio AS SINGLE = graphics.GetDpiX / 96

  DIM ryRatio AS SINGLE = graphics.GetDpiY / 96

  ' // Set the scale transform

  graphics.ScaleTransform(rxRatio, ryRatio)

 

  ' // Create a Font object according to the DPI setting

  DIM font AS CGpFont = CGpFont("Arial", AfxPointsToPixelsX(16) / rxRatio)

 

  ' // Get attributes of font

  DIM logFont AS LOGFONTA

  font.GetLogFontA(@graphics, @logFont)

  ' // Adjust for DPI

  logFont.lfHeight /= rxRatio

 

  ' // Create a second Font object from logFont

  DIM logfontFont AS CGpFont = CGpFont(hdc, @logFont)

 

  ' // Draw text using logfontFont.

  DIM solidbrush AS CGpSolidBrush = GDIP_ARGB(255, 0, 0, 0)

  DIM wszText AS WSTRING * 260 = "Font from a LOGFONTA"

  graphics.DrawString(@wszText, -1, @logfontFont, 0, 0, @solidbrush)

 

END SUB

' ========================================================================================

 

示例

 

' ========================================================================================

' The following example creates a Font object, gets the font attributes from the Font object,

' and uses these attributes (contained in the LOGFONTW structure) to create a second Font

' object. The second Font object is then used to draw text.

' ========================================================================================

SUB Example_GetLogFontW (BYVAL hdc AS HDC)

 

  ' // Create a graphics object from the window device context

  DIM graphics AS CGpGraphics = hdc

  ' // Get the DPI scaling ratio

  DIM rxRatio AS SINGLE = graphics.GetDpiX / 96

  DIM ryRatio AS SINGLE = graphics.GetDpiY / 96

  ' // Set the scale transform

  graphics.ScaleTransform(rxRatio, ryRatio)

 

  ' // Create a Font object according to the DPI setting

  DIM font AS CGpFont = CGpFont("Arial", AfxPointsToPixelsX(16) / rxRatio)

 

  ' // Get attributes of font

  DIM logFont AS LOGFONTW

  font.GetLogFontW(@graphics, @logFont)

  ' // Adjust for DPI

  logFont.lfHeight /= rxRatio

 

  ' // Create a second Font object from logFont

  DIM logfontFont AS CGpFont = CGpFont(hdc, @logFont)

 

  ' // Draw text using logfontFont.

  DIM solidbrush AS CGpSolidBrush = GDIP_ARGB(255, 0, 0, 0)

  DIM wszText AS WSTRING * 260 = "Font from a LOGFONTW"

  graphics.DrawString(@wszText, -1, @logfontFont, 0, 0, @solidbrush)

 

END SUB

' ========================================================================================