Powerbasic Museum 2020-B

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Source Code => Graphics and Multimedia => GDI+ (GDI Plus) => Topic started by: José Roca on June 22, 2008, 05:31:10 AM

Title: GDI+: GdipAddPathString
Post by: José Roca on June 22, 2008, 05:31:10 AM


The following example creates a GraphicsPath object path, adds a NULL-terminated string to path, and then draws path.

C++


VOID Example_AddString(HDC hdc)
{
   Graphics graphics(hdc);
   FontFamily fontFamily(L"Times New Roman");
   GraphicsPath path;

   path.AddString(
      L"Hello World",
      -1,                 // NULL-terminated string
      &fontFamily,
      FontStyleRegular,
      48,
      RectF(50.0f, 50.0f, 150.0f, 100.0f),
      NULL);

   Pen pen(Color(255, 255, 0, 0));
   graphics.DrawPath(&pen, &path);
}


PowerBASIC


SUB GDIP_AddPathString (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pPen AS DWORD
   LOCAL pFontFamily AS DWORD
   LOCAL strFontName AS STRING
   LOCAL strText AS STRING
   LOCAL layoutRect AS RECTF

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreatePath(%FillModeAlternate, pPath)
   strFontName = UCODE$("Arial")
   hStatus = GdipCreateFontFamilyFromName(STRPTR(strFontName), %NULL, pFontFamily)
   strText = UCODE$("Hello World" & $NUL)
   layoutRect.x = 50 : layoutRect.y = 50 : layoutRect.Width = 300 : layoutRect.Height = 50
   hStatus = GdipAddPathString(pPath, STRPTR(strText), -1, pFontFamily, %FontStyleRegular, 48, layoutRect, %NULL)

   ' // Draw the path.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 1, %UnitWorld, pPen)
   hStatus = GdipDrawPath(pGraphics, pPen, pPath)

   ' // Cleanup
   IF pFontFamily THEN GdipDeleteFontFamily(pFontFamily)
   IF pPen THEN GdipDeletePen(pPen)
   IF pPath THEN GdipDeletePath(pPath)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB


(http://www.jose.it-berater.org/captures/GdipAddPathString.png)