VOID Example_Clone(HDC hdc)
{
Graphics graphics(hdc);
// Create a Font object.
Font font(L"Arial", 16);
// Create a clone of the Font object.
Font* cloneFont = font.Clone();
// Draw Text with cloneFont.
SolidBrush solidbrush(Color(255, 0, 0, 0));
WCHAR string[] = L"This is a cloned Font";
graphics.DrawString(string, 21, cloneFont, PointF(0.0f, 0.0f),
&solidbrush);
// Delete the cloned Font object.
delete cloneFont;
}
SUB GDIP_CloneFont (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pFontFamily AS DWORD
LOCAL pFont AS DWORD
LOCAL pClonedFont AS DWORD
LOCAL pSolidBrush AS DWORD
LOCAL strFontName AS STRING
LOCAL strText AS STRING
LOCAL rcf AS RECTF
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create the font
strFontName = UCODE$("Arial")
hStatus = GdipCreateFontFamilyFromName(STRPTR(strFontName), %NULL, pFontFamily)
IF hStatus = %StatusOk AND pFontFamily <> %NULL THEN
hStatus = GdipCreateFont(pFontFamily, 24, %FontStyleRegular, %UnitPoint, pFont)
GdipDeleteFontFamily(pFontFamily)
END IF
' Note: You can use the wrapper function GdiPlusCreateFontFromName to create the font:
' hStatus = GdiPlusCreateFontFromName("Arial", 24, %FontStyleRegular, %UnitPoint, pFont)
' // Create a clone of the font
hStatus = GdipCloneFont(pFont, pClonedFont)
' // Create a solid brush
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 0, 0, 0), pSolidBrush)
' // Draw a string
rcf.x = 30.0! : rcf.y = 30.0!
strText = UCODE$("This is a cloned Font")
hStatus = GdipDrawString(pGraphics, STRPTR(strText), LEN(strText) \ 2, pClonedFont, rcf, %NULL, pSolidBrush)
' // Cleanup
IF pClonedFont THEN GdipDeleteFont(pClonedFont)
IF pFont THEN GdipDeleteFont(pFont)
IF pSolidBrush THEN GdipDeleteBrush(pSolidBrush)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB