Drawing texts with gdiplusX

Published on by Yousfi Benameur

Attached 3 codes for drawing texts with gdiplusX adding  many effects applyed.

1)This code makes some text drawings on imgcanvas  gdiplusX control  on forms.

Drawing texts with effects:
-Embossed
-Engraved
-Bordered
-Reflected
-Shared
-Halo

chose the fontname,fontsize ,colors and then style to apply to the text.

Must have system.app and gdiplusX on source folder ( or point to them on disc) to make this application running.

If you produce an exe and _screen.visible=.f. , locfile(..) blocks the code (then make the sources system.app & gdiplusX.vcx in same folder as your project)

can see also:http://yousfi.over-blog.com/2015/02/drawing-text-with-multi-shadow-effect.html

 

 

*Begin Code

publi m.yrep
m.yrep=addbs(justpath(sys(16,1)))
set defa to (yrep)

Local m.oo
m.oo=.T.
Try
    Do  locfile("System.App")
Catch
    Messagebox("system.app must be in source folder...cancelling!",16+4096,"error")
    m.oo=.F.
Endtry
If m.oo=.F.
    Return .F.
Endi

Set Classlib To Locfile("gdiplusX") AddI
Publi yform
yform=Newobject("ytext_effects")
Release Classlib "gdiplusX"
yform.Show
Read Events
Retu
*
Define Class ytext_effects As Form
    Height = 689
    Width = 949
    ShowWindow = 2
    ScrollBars = 2
    AutoCenter = .T.
    Caption = "text effects with gdiplusX"
    BackColor = Rgb(0,0,0)
    Name = "Form1"

    Add Object yembossed1 As yembossed With ;
        Height = 36, ;
        Left = 12, ;
        Top = 84, ;
        Width = 132, ;
        xtext = "Hello World1 !", ;
        xsize = 14, ;
        xfont = "Tahoma", ;
        lcstyle = "B", ;
        Name = "Yembossed1"

    Add Object yembossed2 As yembossed With ;
        Height = 132, ;
        Left = 180, ;
        Top = 12, ;
        Width = 396, ;
        xtext = "Hello World2!", ;
        xsize = 28, ;
        lcstyle = "N", ;
        Name = "Yembossed2"

    Add Object yembossed3 As yembossed With ;
        Height = 63, ;
        Left = 12, ;
        Top = 144, ;
        Width = 379, ;
        xtext = "Hello World3 ! engraved", ;
        xsize = 36, ;
        xfont = "Georgia", ;
        lcstyle = "BI", ;
        xtype = 2, ;
        Name = "Yembossed3"

    Add Object yembossed4 As yembossed With ;
        Height = 133, ;
        Left = 396, ;
        Top = 132, ;
        Width = 552, ;
        xtext = "Hello World3 ! bordered", ;
        xsize = 36, ;
        xfont = "Georgia", ;
        lcstyle = "BI", ;
        xtype = 3, ;
        xbackcolor2 = (Rgb(255,255,255)), ;
        xbackcolor1 = 255, ;
        Name = "Yembossed4"

    Add Object yembossed5 As yembossed With ;
        Height = 133, ;
        Left = 24, ;
        Top = 300, ;
        Width = 456, ;
        xtext = "Hello World3 !engraved", ;
        xsize = 48, ;
        xfont = "Georgia", ;
        lcstyle = "BI", ;
        xtype = 2, ;
        xbackcolor2 = (Rgb(255,255,255)), ;
        xbackcolor1 = 255, ;
        Name = "Yembossed5"

    Add Object yembossed6 As yembossed With ;
        Height = 133, ;
        Left = 492, ;
        Top = 276, ;
        Width = 456, ;
        xtext = "Hello World3 embossed", ;
        xsize = 48, ;
        xfont = "Georgia", ;
        lcstyle = "BI", ;
        xtype = 1, ;
        xbackcolor2 = (Rgb(255,255,255)), ;
        xbackcolor1 = 255, ;
        Name = "Yembossed6"

    Add Object yembossed7 As yembossed With ;
        Height = 96, ;
        Left = 24, ;
        Top = 432, ;
        Width = 432, ;
        xtext = "Hello World Reflected!", ;
        xsize = 24, ;
        xfont = "Georgia", ;
        lcstyle = "BI", ;
        xtype = 4, ;
        Name = "Yembossed7"

    Add Object yembossed8 As yembossed With ;
        Height = 96, ;
        Left = 480, ;
        Top = 408, ;
        Width = 468, ;
        xtext = "Hello World Reflected!", ;
        xsize = 24, ;
        xfont = "Georgia", ;
        lcstyle = "BI", ;
        xtype = 5, ;
        Name = "Yembossed8"

    Add Object yembossed9 As yembossed With ;
        Height = 93, ;
        Left = 576, ;
        Top = 12, ;
        Width = 379, ;
        xtext = "Hello World3 !Halo", ;
        xsize = 36, ;
        xfont = "Georgia", ;
        lcstyle = "BI", ;
        xtype = 6, ;
        xcolorshadow = (Rgb(0,255,255)), ;
        Name = "Yembossed9"

    Add Object yembossed10 As yembossed With ;
        Height = 84, ;
        Left = 12, ;
        Top = 216, ;
        Width = 504, ;
        xtext = "Hello World3 ! engraved", ;
        xsize = 36, ;
        xfont = "Georgia", ;
        lcstyle = "BI", ;
        xtype = 1, ;
        Name = "Yembossed10"

    Add Object yembossed11 As yembossed With ;
        Height = 184, ;
        Left = 108, ;
        Top = 500, ;
        Width = 672, ;
        xtext = "Hello World3 ! engraved", ;
        xsize = 14, ;
        xfont = "Georgia", ;
        lcstyle = "BI", ;
        xtype = 2, ;
        xcolorshadow = (Rgb(255,255,255)), ;
        xcolormain = (Rgb(70,255,80)), ;
        xbackcolor2 = 67801, ;
        xbackcolor1 = (Rgb(21,205,145)), ;
        Name = "Yembossed11"

    Add Object command1 As CommandButton With ;
        Top = 12, ;
        Left = 24, ;
        Height = 36, ;
        Width = 38, ;
        Anchor = 768, ;
        Picture = Home(1)+"graphics\icons\win95\explorer.ico", ;
        Caption = "", ;
        MousePointer = 15, ;
        Name = "Command1"

    Add Object command2 As CommandButton With ;
        Top = 18, ;
        Left = 70, ;
        Height = 25, ;
        Width = 50, ;
        Anchor = 768, ;
        Caption = "test", ;
        MousePointer = 15, ;
        BackColor = Rgb(0,255,0), ;
        Name = "Command2"

    Procedure Destroy
        Clea Events
    Endproc

    Procedure yembossed10.Setup
        TEXT to this.xtext noshow
        Terre, soleil vallons, belle et douce nature
        je vous dois une larme au bord de mon tombeau
        l'air est si parfumé, la li*umière est si pure
        au regrd d'un mourrant le soleil est si beau
        ENDTEXT
        This.xsize=12
        This.lcstyle="BI"
    Endproc

    Procedure yembossed11.Setup
        TEXT to this.xtext noshow
        Terre, soleil vallons, belle et douce nature
        je vous dois une larme au bord de mon tombeau
        l'air est si parfumé, la li*umière est si pure
        au regrd d'un mourrant le soleil est si beau
        Terre, soleil vallons, belle et douce nature
        je vous dois une larme au bord de mon tombeau
        l'air est si parfumé, la li*umière est si pure
        au regrd d'un mourrant le soleil est si beau
        ENDTEXT
        This.xsize=14
        This.lcstyle="BI"
    Endproc

    Procedure command1.Click
         Run/N EXPLORER &yrep
    Endproc

    Procedure command2.Click
        Publi ytest
        ytest=Newobject("test")
        ytest.Show(1)

    Endproc

Enddefine
*
*!*
*!*
*!*

*class yembossed.vcx
Define Class yembossed As imgcanvas
    lcstyle = "BI"
    xfont = "Arial black"
    xsize = 24
    xbackcolor1 = (Rgb(215,255,145))
    xtext = "Hello World"
    xtype = 1
    xbackcolor2 = 255
    epaisseur = 4
    xcolormain = (Rgb(0,255,0))
    xcolorshadow = 0
    rendermode = 4
    drawwheninvisible = .T.
    Name = "yembossed"

    Procedure beforedraw
        This.Parent.LockScreen=.T.
        Local loFont As xfcFont
        Local loFontFamily As xfcFontFamily
        Do Case

            Case This.xtype=1   &&embossed
                With _Screen.System.Drawing
                    This.Clear()

                    Do Case
                        Case This.lcstyle == "B"
                            loStyle = .FontStyle.Bold
                        Case This.lcstyle == "I"
                            loStyle = .FontStyle.Italic
                        Case This.lcstyle == "BI"
                            loStyle = .FontStyle.BoldItalic
                        Otherwise
                            loStyle = .FontStyle.Regular
                    Endcase

                    loFont = .Font.New(This.xfont,This.xsize, loStyle)

                    This.oGfx.DrawString(This.xtext, loFont, ;
                        .SolidBrush.New(.Color.FromRGB(This.xbackcolor1)), ;
                        This.Rectangle)

                    This.oGfx.TranslateTransform(1, 1)
                    This.oGfx.DrawString(This.xtext, loFont, ;
                        .SolidBrush.New(.Color.FromRGB(This.Parent.BackColor)), ;
                        This.Rectangle)

                    This.oGfx.ResetTransform()
                Endwith

            Case This.xtype=2  &&engraved

                With _Screen.System.Drawing
                    This.Clear()

                    Do Case
                        Case This.lcstyle == "B"
                            loStyle = .FontStyle.Bold
                        Case This.lcstyle == "I"
                            loStyle = .FontStyle.Italic
                        Case This.lcstyle == "BI"
                            loStyle = .FontStyle.BoldItalic
                        Otherwise
                            loStyle = .FontStyle.Regular
                    Endcase

                    loFont = .Font.New(This.xfont,This.xsize, loStyle)

                    This.oGfx.DrawString(This.xtext, loFont, ;
                        .SolidBrush.New(.Color.FromRGB(This.xbackcolor1)), ;
                        This.Rectangle)

                    This.oGfx.TranslateTransform(-1, -1)
                    This.oGfx.DrawString(This.xtext, loFont, ;
                        .SolidBrush.New(.Color.FromRGB(This.Parent.BackColor)), ;
                        This.Rectangle)

                    This.oGfx.ResetTransform()

                Endwith

            Case This.xtype=3  &&text with border
                Local loFont As xfcFont
                With _Screen.System.Drawing
                    This.Clear(.Color.transparent)

                    Do Case
                        Case This.lcstyle == "B"
                            loStyle = .FontStyle.Bold
                        Case This.lcstyle == "I"
                            loStyle = .FontStyle.Italic
                        Case This.lcstyle == "BI"
                            loStyle = .FontStyle.BoldItalic
                        Otherwise
                            loStyle = .FontStyle.Regular
                    Endcase

                    * Create a GraphicsPath object.
                    Local loPath As xfcGraphicsPath
                    loPath = .Drawing2D.GraphicsPath.New()

                    * Add the string in the chosen style.
                    loPath.AddString(This.xtext, ;
                        .FontFamily.New(This.xfont), ;
                        loStyle, ;
                        this.xsize, ;
                        .Point.New(0, 0))

                    * Using a suitable pen...
                    Local loPen As xfcPen
                    loPen = .Pen.New(.Color.FromRGB(This.xbackcolor1),This.epaisseur)

                    * Choose an appropriate smoothing mode for the border.
                    This.oGfx.SmoothingMode = .Drawing2D.SmoothingMode.AntiAlias

                    * Draw around the outline of the path
                    This.oGfx.DrawPath(loPen, loPath)

                    * Redraw the original text
                    This.oGfx.FillPath(.SolidBrush.New(.Color.FromRGB(This.xbackcolor2)), loPath)
                Endwith

            Case This.xtype=4   &&reflected text
                Local loFont As xfcFont
                Local loFontFamily As xfcFontFamily

                With _Screen.System.Drawing
                    This.Clear()

                    Do Case
                        Case This.lcstyle == "B"
                            loStyle = .FontStyle.Bold
                        Case This.lcstyle == "I"
                            loStyle = .FontStyle.Italic
                        Case This.lcstyle == "BI"
                            loStyle = .FontStyle.BoldItalic
                        Otherwise
                            loStyle = .FontStyle.Regular
                    Endcase

                    loFont = .Font.New(This.xfont, This.xsize, loStyle)
                    loFontFamily = .FontFamily.New(This.xfont)

                    This.oGfx.DrawString(This.xtext, loFont, ;
                        .SolidBrush.New(.Color.FromRGB(This.xbackcolor1)), ;
                        This.Rectangle)

                    Local lnCy, lnLineHeight, lnLineAscent, lnLineSpacing
                    lnLineAscent = loFontFamily.GetCellAscent(loStyle)
                    lnLineSpacing = loFontFamily.GetLineSpacing(loStyle)
                    lnLineHeight = loFont.GetHeight(This.oGfx)
                    lnCy = lnLineHeight * lnLineAscent / lnLineSpacing

                    This.oGfx.ScaleTransform(1, -1)
                    This.oGfx.DrawString(This.xtext, loFont, ;
                        .SolidBrush.New(.Color.FromRGB(This.xbackcolor2)), ;
                        .PointF.New(0, -(lnCy*2)-1))

                    This.oGfx.ResetTransform()
                Endwith

            Case This.xtype=5  &&reflected é sheared
                Local lnShear
                lnShear =1.00

                Local loFont As xfcFont
                Local loFontFamily As xfcFontFamily
                Local loMatrix As xfcMatrix

                With _Screen.System.Drawing
                    This.Clear()

                    Do Case
                        Case This.lcstyle == "B"
                            loStyle = .FontStyle.Bold
                        Case This.lcstyle == "I"
                            loStyle = .FontStyle.Italic
                        Case This.lcstyle == "BI"
                            loStyle = .FontStyle.BoldItalic
                        Otherwise
                            loStyle = .FontStyle.Regular
                    Endcase

                    loFont = .Font.New(This.xfont ,This.xsize, loStyle)
                    loFontFamily = .FontFamily.New(This.xfont)

                    This.oGfx.DrawString(This.xtext, loFont, ;
                        .SolidBrush.New(.Color.FromRGB(This.xbackcolor1)), ;
                        This.Rectangle)

                    Local lnCy, lnLineHeight, lnLineAscent, lnLineSpacing
                    lnLineAscent = loFontFamily.GetCellAscent(loStyle)
                    lnLineSpacing = loFontFamily.GetLineSpacing(loStyle)
                    lnLineHeight = loFont.GetHeight(This.oGfx)
                    lnCy = lnLineHeight * lnLineAscent / lnLineSpacing

                    loMatrix = .Drawing2D.Matrix.New()
                    loMatrix.Shear(lnShear, 0)
                    loMatrix.Scale(1, -1)

                    This.oGfx.MultiplyTransform(loMatrix)

                    This.oGfx.DrawString(This.xtext, loFont, ;
                        .SolidBrush.New(.Color.FromRGB(This.xbackcolor2)), ;
                        .PointF.New(0 + (-0.82 * lnLineHeight * lnShear) , -(lnCy*2)-1))

                    This.oGfx.ResetTransform()

                Endwith

            Case This.xtype=6   &&halo
                Local loFont As xfcFont
                With _Screen.System.Drawing
                    This.Clear()

                    Do Case
                        Case This.lcstyle == "B"
                            loStyle = .FontStyle.Bold
                        Case This.lcstyle == "I"
                            loStyle = .FontStyle.Italic
                        Case This.lcstyle == "BI"
                            loStyle = .FontStyle.BoldItalic
                        Otherwise
                            loStyle = .FontStyle.Regular
                    Endcase

                    * Create a bitmap in a fixed ratio to the original drawing area.
                    Local loBmp As xfcBitmap
                    loBmp = .Bitmap.New(This.Width / 5, This.Height / 5)

                    * Create a GraphicsPath object.
                    Local loPath As xfcGraphicsPath
                    loPath = .Drawing2D.GraphicsPath.New()

                    * Add the string in the chosen style.
                    loPath.AddString(This.xtext, ;
                        .FontFamily.New(This.xfont), ;
                        loStyle, ;
                        this.xsize, ;
                        .Point.New(0, 0), ;
                        .StringFormat.GenericTypographic)

                    * Get the graphics object for the image.
                    Local loGfx As xfcGraphics
                    loGfx = .Graphics.FromImage(loBmp)
                    loGfx.Clear(.Color.transparent)    &&white)
                    * Create a matrix that shrinks the drawing output by the fixed ratio.
                    Local loMatrix As xfcMatrix
                    loMatrix = .Drawing2D.Matrix.New(1/5, 0, 0, 1/5, -1/5, -1/5)

                    * Choose an appropriate smoothing mode for the halo.
                    loGfx.SmoothingMode = .Drawing2D.SmoothingMode.AntiAlias

                    * Transform the graphics object so that the same half may be used for both halo and text output.
                    loGfx.Transform = loMatrix

                    * Using a suitable pen...
                    Local loPen As xfcPen
                    loPen = .Pen.New(.Color.FromRGB(This.xcolorshadow))

                    * Draw around the outline of the path
                    loGfx.DrawPath(loPen, loPath)

                    * and then fill in for good measure.
                    loGfx.FillPath( .SolidBrush.New(.Color.FromRGB(This.xcolorshadow)), loPath)

                    * setup the smoothing mode for path drawing
                    This.oGfx.SmoothingMode = .Drawing2D.SmoothingMode.AntiAlias

                    * and the interpolation mode for the expansion of the halo bitmap
                    This.oGfx.InterpolationMode = .Drawing2D.InterpolationMode.HighQualityBicubic

                    * expand the halo making the edges nice and fuzzy.
                    This.oGfx.DrawImage(loBmp, This.Rectangle, 0, 0, ;
                        loBmp.Width, loBmp.Height, .GraphicsUnit.Pixel)

                    * Redraw the original text
                    This.oGfx.FillPath(.SolidBrush.New(.Color.FromRGB(This.xcolormain)), loPath)
                    *this.save("c:\myImage.png",.imaging.imageformat.png)
                Endwith

            Otherwise
                *anything
        Endcase

        This.Parent.LockScreen=.F.
        Return
    Endproc

    Procedure RightClick
        If Messagebox("Save as image ?",4+64+4096,"Saving")=6
            Local m.lcDir
            m.lcDir=m.yrep+"images\"
            If !Directory(m.lcDir)
                Md (m.lcDir)
            Endi
            Local m.lcdest
            m.lcdest=m.lcDir+"img_"+Sys(2015)+".png"
            This.obmp.Save(m.lcdest,_Screen.System.Drawing.imaging.imageformat.png)
            Messagebox("Saved as image:"+m.lcdest,0+32+4096,"Saving as image",1500)

        Endi
    Endproc

Enddefine
*
*-- EndDefine: yembossed

 

*test form

*Can chose save button to save as png image or rightclick on the canvas for same operation
Define Class test As Form
    BorderStyle = 2
    Height = 316
    Width = 658
    ShowWindow = 2
    AutoCenter = .T.
    Caption = "Text_effects with gdiplusX"
    MaxButton = .F.
    BackColor = Rgb(0,0,0)
    Name = "Form1"

    Add Object command1 As CommandButton With ;
        Top = 240, ;
        Left = 48, ;
        Height = 25, ;
        Width = 109, ;
        Caption = "xBackcolor1", ;
        Name = "Command1"

    Add Object command2 As CommandButton With ;
        Top = 240, ;
        Left = 192, ;
        Height = 25, ;
        Width = 133, ;
        Caption = "xfont/xsize", ;
        Name = "Command2"

    Add Object text1 As TextBox With ;
        Height = 25, ;
        Left = 336, ;
        Top = 240, ;
        Width = 229, ;
        value="Hello World"
    Name = "Text1"

    Add Object combo1 As ComboBox With ;
        Height = 25, ;
        Left = 204, ;
        Top = 276, ;
        Width = 109, ;
        Name = "Combo1"

    Add Object yembossed1 As yembossed With ;
        Height = 204, ;
        Left = 12, ;
        Top = 12, ;
        Width = 636, ;
        lcstyle = "BI", ;
        xcolorshadow = (Rgb(255,0,255)), ;
        xsize = 48, ;
        Name = "Yembossed1"

    Add Object command3 As CommandButton With ;
        Top = 279, ;
        Left = 49, ;
        Height = 25, ;
        Width = 109, ;
        Caption = "xBackcolor2", ;
        Name = "Command3"

    Add Object command4 As CommandButton With ;
        Top = 240, ;
        Left = 576, ;
        Height = 25, ;
        Width = 61, ;
        Caption = "Save", ;
        Name = "Command4"

    Procedure command1.Click
        Local m.xcolor
        m.xcolor=Getcolor()
        If m.xcolor=-1
            Return .F.
        Endi
        With Thisform.yembossed1
            .xbackcolor1=m.xcolor
            .Draw
        Endwith
    Endproc

    Procedure command2.Click
        Local xfont
        m.xfont=Getfont()
        If Empty(m.xfont)
            Return .F.
        Endi

        With Thisform.yembossed1
            .xfont=Getwordnum(m.xfont,1,",")
            .xsize=Int(Val(Getwordnum(m.xfont,2,",")))
            .Draw
        Endwith
    Endproc

    Procedure text1.Valid
        With Thisform.yembossed1
            .xtext=This.Value
            .Draw
        Endwith
    Endproc

    Procedure combo1.Init
        With This
            .AddItem("1.text embossed")
            .AddItem("2.engraved")
            .AddItem("3.with borders")
            .AddItem("4.reflected")
            .AddItem("5.reflected & sheared")
            .AddItem("6.halo")
            .ListIndex=1
            .Value=1
            .Style=2
        Endwith
    Endproc

    Procedure combo1.Click

        With Thisform.yembossed1
            .xtype=This.Value
            .Draw
        Endwith
    Endproc

    Procedure command3.Click
        Local m.xcolor
        m.xcolor=Getcolor()
        If m.xcolor=-1
            Return .F.
        Endi
        With Thisform.yembossed1
            .xbackcolor2=m.xcolor
            .Draw
        Endwith
    Endproc

    Procedure command4.Click
      
 Local m.lcDir
            m.lcDir=m.yrep+"images\"
            If !Directory(m.lcDir)
                Md (m.lcDir)
            Endi
            Local m.lcdest
            m.lcdest=m.lcDir+"img_"+Sys(2015)+".png"
    

     Thisform.yembossed1.obmp.Save(m.lcdest,;
_Screen.System.Drawing.imaging.imageformat.png)  &&jpeg,bmp,gif....
        Messagebox(m.yrep+Sys(2015)+".png"+" ....saved!",0+32+4096,"",600)
    Endproc

Enddefine
*
*-- EndDefine: test
*

*-Endcode

 

Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX

*2)This draws the 6 types text effects on form with gdiplusX-Rightclick to save each image as PNG.
*Begin code

Publi m.yrep
m.yrep=Addbs(Justpath(Sys(16,1)))
Set Defa To (yrep)
Publi yform
Set Classlib To Locfile("gdiplusX.vcx") AddI
yform=Newobject("ytext_6types")
Release Classlib "gdiplusX"
yform.Show
Read Events
Return
*
Define Class ytext_6types As Form
    Top = -7
    Left = 110
    Height = 568
    Width = 472
    AutoCenter=.T.
    ShowWindow = 2
    ShowTips = .T.
    Caption = "GdiplusX samples  text  styles types"
    BackColor = Rgb(255,255,255)
    mode = 0
    Name = "Form1"

    Add Object imgcanvas1 As imgcanvas With ;
        Anchor = 15, ;
        Height = 60, ;
        Left = 12, ;
        Top = 120, ;
        Width = 456, ;
        smoothingmode = 0, ;
        Name = "Imgcanvas1"

    Add Object label2 As Label With ;
        AutoSize = .T., ;
        BackStyle = 0, ;
        Caption = "Embossed", ;
        Height = 17, ;
        Left = 168, ;
        Top = 100, ;
        Width = 63, ;
        TabIndex = 5, ;
        Name = "Label2"

    Add Object label3 As Label With ;
        AutoSize = .T., ;
        BackStyle = 0, ;
        Caption = "Engraved", ;
        Height = 17, ;
        Left = 180, ;
        Top = 181, ;
        Width = 54, ;
        TabIndex = 5, ;
        Name = "Label3"

    Add Object imgcanvas2 As imgcanvas With ;
        Anchor = 15, ;
        Enabled = .F., ;
        Height = 60, ;
        Left = 12, ;
        Top = 202, ;
        Width = 456, ;
        smoothingmode = 0, ;
        Name = "Imgcanvas2"

    Add Object imgcanvas3 As imgcanvas With ;
        Anchor = 15, ;
        BackStyle = 0, ;
        Height = 84, ;
        Left = 14, ;
        Top = 282, ;
        Width = 454, ;
        smoothingmode = 0, ;
        Name = "Imgcanvas3"

    Add Object label1 As Label With ;
        AutoSize = .T., ;
        BackStyle = 0, ;
        Caption = "text with borders", ;
        Height = 17, ;
        Left = 184, ;
        Top = 264, ;
        Width = 91, ;
        TabIndex = 5, ;
        Name = "Label1"

    Add Object imgcanvas4 As imgcanvas With ;
        Anchor = 15, ;
        Height = 60, ;
        Left = 13, ;
        Top = 391, ;
        Width = 455, ;
        smoothingmode = 0, ;
        Name = "Imgcanvas4"

    Add Object label4 As Label With ;
        AutoSize = .T., ;
        BackStyle = 0, ;
        Caption = "Reflected", ;
        Height = 17, ;
        Left = 192, ;
        Top = 369, ;
        Width = 54, ;
        TabIndex = 5, ;
        Name = "Label4"

    Add Object label5 As Label With ;
        AutoSize = .T., ;
        BackStyle = 0, ;
        Caption = "Reflected and sheared", ;
        Height = 17, ;
        Left = 144, ;
        Top = 455, ;
        Width = 127, ;
        TabIndex = 5, ;
        Name = "Label5"

    Add Object imgcanvas5 As imgcanvas With ;
        Anchor = 15, ;
        Height = 60, ;
        Left = 12, ;
        Top = 477, ;
        Width = 456, ;
        smoothingmode = 0, ;
        Name = "Imgcanvas5"

    Add Object label6 As Label With ;
        AutoSize = .T., ;
        FontSize = 9, ;
        WordWrap = .T., ;
        BackStyle = 0, ;
        Caption = "Right click on each  imgcanvas to save it as PNG", ;
        Height = 32, ;
        Left = 29, ;
        Top = 538, ;
        Width = 390, ;
        ForeColor = Rgb(255,0,0), ;
        Name = "Label6"

    Add Object imgcanvas6 As imgcanvas With ;
        Anchor = 15, ;
        BackStyle = 0, ;
        Height = 84, ;
        Left = 9, ;
        Top = 14, ;
        Width = 459, ;
        smoothingmode = 0, ;
        Name = "Imgcanvas6"

    Add Object label7 As Label With ;
        AutoSize = .T., ;
        BackStyle = 0, ;
        Caption = "Halo", ;
        Height = 17, ;
        Left = 226, ;
        Top = 0, ;
        Width = 28, ;
        TabIndex = 5, ;
        Name = "Label7"

    Procedure Init
        With Thisform
            For i=1 To .ControlCount
                If Lower(.Controls(i).Class)="imgcanvas"
                    Bindevent(.Controls(i),"rightclick",Thisform,"my")
                Endi
            Endfor
        Endwith

    Endproc

    Procedure imgcanvas1.beforedraw
        Local lcStyle
        xtext="Drawing texts"
        lcStyle="N"

        xfont="Arial Black"
        xsize=28
        loStyle="B"
        xBackColor=255

        Local loFont As xfcFont
        Local loFontFamily As xfcFontFamily

        With _Screen.System.Drawing
            This.Clear()

            Do Case
                Case lcStyle == "B"
                    loStyle = .FontStyle.Bold
                Case lcStyle == "I"
                    loStyle = .FontStyle.Italic
                Case lcStyle == "BI"
                    loStyle = .FontStyle.BoldItalic
                Otherwise
                    loStyle = .FontStyle.Regular
            Endcase

            loFont = .Font.New(xfont,xsize, loStyle)

            This.oGfx.DrawString(xtext, loFont, ;
                .SolidBrush.New(.Color.FromRGB(xBackColor)), ;
                This.Rectangle)

            This.oGfx.TranslateTransform(1, 1)
            This.oGfx.DrawString(xtext, loFont, ;
                .SolidBrush.New(.Color.FromRGB(This.Parent.BackColor)), ;
                This.Rectangle)

            This.oGfx.ResetTransform()
        Endwith
        Return
    Endproc

    Procedure imgcanvas2.beforedraw
        Local lcStyle
        xtext="Drawing texts"
        lcStyle="N"

        xfont="Arial Black"
        xsize=28
        loStyle="B"
        xBackColor=Rgb(0,255,0)

        Local loFont As xfcFont
        Local loFontFamily As xfcFontFamily

        With _Screen.System.Drawing
            This.Clear()

            Do Case
                Case lcStyle == "B"
                    loStyle = .FontStyle.Bold
                Case lcStyle == "I"
                    loStyle = .FontStyle.Italic
                Case lcStyle == "BI"
                    loStyle = .FontStyle.BoldItalic
                Otherwise
                    loStyle = .FontStyle.Regular
            Endcase

            loFont = .Font.New(xfont,xsize, loStyle)

            This.oGfx.DrawString(xtext, loFont, ;
                .SolidBrush.New(.Color.FromRGB(xBackColor)), ;
                This.Rectangle)

            This.oGfx.TranslateTransform(-1, -1)
            This.oGfx.DrawString(xtext, loFont, ;
                .SolidBrush.New(.Color.FromRGB(This.Parent.BackColor)), ;
                This.Rectangle)

            This.oGfx.ResetTransform()
        Endwith
        Return
    Endproc

    Procedure imgcanvas3.beforedraw
        Local lcStyle
        lcStyle = "BI"
        xtext="GdiPlusX version beta"
        xfont="Arial Black"
        xsize=32
        xBackcolor1=Rgb(0,255,0)
        xbackcolor2=Rgb(0,0,55)
        epaisseur=4

        Local loFont As xfcFont

        With _Screen.System.Drawing
            This.Clear(.Color.White)

            Do Case
                Case lcStyle == "B"
                    loStyle = .FontStyle.Bold
                Case lcStyle == "I"
                    loStyle = .FontStyle.Italic
                Case lcStyle == "BI"
                    loStyle = .FontStyle.BoldItalic
                Otherwise
                    loStyle = .FontStyle.Regular
            Endcase

            * Create a GraphicsPath object.
            Local loPath As xfcGraphicsPath
            loPath = .Drawing2D.GraphicsPath.New()

            * Add the string in the chosen style.
            loPath.AddString(xtext, ;
                .FontFamily.New(xfont), ;
                loStyle, ;
                xsize, ;
                .Point.New(0, 0))

            * Using a suitable pen...
            Local loPen As xfcPen
            loPen = .Pen.New(.Color.FromRGB(xBackcolor1),epaisseur)

            * Choose an appropriate smoothing mode for the border.
            This.oGfx.smoothingmode = .Drawing2D.smoothingmode.AntiAlias

            * Draw around the outline of the path
            This.oGfx.DrawPath(loPen, loPath)

            * Redraw the original text
            This.oGfx.FillPath(.SolidBrush.New(.Color.FromRGB(xbackcolor2)), loPath)

        Endwith
        Return
    Endproc


    Procedure imgcanvas4.beforedraw
        Local lcStyle
        lcStyle="B"
        xfont="Arial Black"
        xsize=24
        xBackcolor1=255
        xbackcolor2=Rgb(0,22,0)
        xtext="Drawing texts"

        Local loFont As xfcFont
        Local loFontFamily As xfcFontFamily

        With _Screen.System.Drawing
            This.Clear()

            Do Case
                Case lcStyle == "B"
                    loStyle = .FontStyle.Bold
                Case lcStyle == "I"
                    loStyle = .FontStyle.Italic
                Case lcStyle == "BI"
                    loStyle = .FontStyle.BoldItalic
                Otherwise
                    loStyle = .FontStyle.Regular
            Endcase

            loFont = .Font.New(xfont, xsize, loStyle)
            loFontFamily = .FontFamily.New(xfont)

            This.oGfx.DrawString(xtext, loFont, ;
                .SolidBrush.New(.Color.FromRGB(xBackcolor1)), ;
                This.Rectangle)

            Local lnCy, lnLineHeight, lnLineAscent, lnLineSpacing
            lnLineAscent = loFontFamily.GetCellAscent(loStyle)
            lnLineSpacing = loFontFamily.GetLineSpacing(loStyle)
            lnLineHeight = loFont.GetHeight(This.oGfx)
            lnCy = lnLineHeight * lnLineAscent / lnLineSpacing

            This.oGfx.ScaleTransform(1, -1)
            This.oGfx.DrawString(xtext, loFont, ;
                .SolidBrush.New(.Color.FromRGB(xbackcolor2)), ;
                .PointF.New(0, -(lnCy*2)-1))

            This.oGfx.ResetTransform()
        Endwith
        Return
    Endproc

    Procedure imgcanvas5.beforedraw
        Local lcStyle,lnShear
        lcStyle="B"
        xfont="Arial Black"
        xsize=24
        xBackcolor1=255
        xbackcolor2=Rgb(0,22,0)
        xtext="Drawing texts"
        lnShear =1.00

        Local loFont As xfcFont
        Local loFontFamily As xfcFontFamily
        Local loMatrix As xfcMatrix

        With _Screen.System.Drawing
            This.Clear()

            Do Case
                Case lcStyle == "B"
                    loStyle = .FontStyle.Bold
                Case lcStyle == "I"
                    loStyle = .FontStyle.Italic
                Case lcStyle == "BI"
                    loStyle = .FontStyle.BoldItalic
                Otherwise
                    loStyle = .FontStyle.Regular
            Endcase

            loFont = .Font.New(xfont ,xsize, loStyle)
            loFontFamily = .FontFamily.New(xfont)

            This.oGfx.DrawString(xtext, loFont, ;
                .SolidBrush.New(.Color.FromRGB(xBackcolor1)), ;
                This.Rectangle)

            Local lnCy, lnLineHeight, lnLineAscent, lnLineSpacing
            lnLineAscent = loFontFamily.GetCellAscent(loStyle)
            lnLineSpacing = loFontFamily.GetLineSpacing(loStyle)
            lnLineHeight = loFont.GetHeight(This.oGfx)
            lnCy = lnLineHeight * lnLineAscent / lnLineSpacing


            loMatrix = .Drawing2D.Matrix.New()
            loMatrix.Shear(lnShear, 0)
            loMatrix.Scale(1, -1)

            This.oGfx.MultiplyTransform(loMatrix)

            This.oGfx.DrawString(xtext, loFont, ;
                .SolidBrush.New(.Color.FromRGB(xbackcolor2)), ;
                .PointF.New(0 + (-0.82 * lnLineHeight * lnShear) , -(lnCy*2)-1))

            This.oGfx.ResetTransform()

        Endwith
        Return
    Endproc

    Procedure imgcanvas6.beforedraw
        Local lcStyle
        lcStyle = "B"
        xtext="Drawing texts"
        xfontName="Arial Black"
        xsize=40

        xcolormain=Rgb(0,255,0)
        xcolorShadow=0

        Local loFont As xfcFont

        With _Screen.System.Drawing
            This.Clear()


            Do Case
                Case lcStyle == "B"
                    loStyle = .FontStyle.Bold
                Case lcStyle == "I"
                    loStyle = .FontStyle.Italic
                Case lcStyle == "BI"
                    loStyle = .FontStyle.BoldItalic
                Otherwise
                    loStyle = .FontStyle.Regular
            Endcase

            * Create a bitmap in a fixed ratio to the original drawing area.
            Local loBmp As xfcBitmap
            loBmp = .Bitmap.New(This.Width / 5, This.Height / 5)

            * Create a GraphicsPath object.
            Local loPath As xfcGraphicsPath
            loPath = .Drawing2D.GraphicsPath.New()

            * Add the string in the chosen style.
            loPath.AddString(xtext, ;
                .FontFamily.New(xfontName), ;
                loStyle, ;
                xsize, ;
                .Point.New(0, 0), ;
                .StringFormat.GenericTypographic)

            * Get the graphics object for the image.
            Local loGfx As xfcGraphics
            loGfx = .Graphics.FromImage(loBmp)
            loGfx.Clear(.Color.White)
            * Create a matrix that shrinks the drawing output by the fixed ratio.
            Local loMatrix As xfcMatrix
            loMatrix = .Drawing2D.Matrix.New(1/5, 0, 0, 1/5, -1/5, -1/5)

            * Choose an appropriate smoothing mode for the halo.
            loGfx.smoothingmode = .Drawing2D.smoothingmode.AntiAlias

            * Transform the graphics object so that the same half may be used for both halo and text output.
            loGfx.Transform = loMatrix

            * Using a suitable pen...
            Local loPen As xfcPen
            loPen = .Pen.New(.Color.FromRGB(xcolorShadow))

            * Draw around the outline of the path
            loGfx.DrawPath(loPen, loPath)

            * and then fill in for good measure.
            loGfx.FillPath( .SolidBrush.New(.Color.FromRGB(xcolorShadow)), loPath)

            * setup the smoothing mode for path drawing
            This.oGfx.smoothingmode = .Drawing2D.smoothingmode.AntiAlias

            * and the interpolation mode for the expansion of the halo bitmap
            This.oGfx.InterpolationMode = .Drawing2D.InterpolationMode.HighQualityBicubic

            * expand the halo making the edges nice and fuzzy.
            This.oGfx.DrawImage(loBmp, This.Rectangle, 0, 0, ;
                loBmp.Width, loBmp.Height, .GraphicsUnit.Pixel)

            * Redraw the original text
            This.oGfx.FillPath(.SolidBrush.New(.Color.FromRGB(xcolormain)), loPath)
 This.Save([c:\myImage.png],;
.imaging.imageformat.png)
        Endwith
        Return
    Endproc
    Procedure MY
        *--- aevent create an array laEvents
        Aevents( myArray, 0)
        *--- reference the calling object
        loObject = myArray[1]

        loObject.obmp.Save(m.yrep+Sys(2015)+[.png],;
_Screen.System.Drawing.imaging.imageformat.png)    

    Messagebox(m.yrep+Sys(2015)+".png"+"....saved",0+32+4096,"",600)
    Endproc

    Procedure Destroy
        Clea Events
    Endproc


Enddefine
*
*-- EndDefine: ytext_6types

*End code

 

Drawing texts with gdiplusX

*3*This is a small workshop to draw any text with rendered effects of gdiplusX
*can set fontname,fontsize,colors...change text,make a logo...
*can make background as picture ,gradient or no background as you can see in screen shots below.
*can save as png image (jpg,bmp,gif...) or show in mspaint the imgcanvas contents

*the code ask to system.aap and gdiplusX (if noy in source folder).

 

*Begin Code

Publi m.yrep
m.yrep= Addbs(Justpath(Sys(16,1)))
Set Defa To (yrep)

Do Locfile("SYSTEM.app")
Set Classlib To Locfile("gdiplusX") AddI
Set Classlib To Home(1)+"samples\classes\samples.vcx" AddI

Publi yform
yform=Newobject("ydtext")
Release Classlib  Home(1)+"samples\classes\samples.vcx"
Release Classlib "gdiplusX"
yform.Show
Read Events
Return
*
Define Class ydtext As Form
    Height = 581
    Width = 898
    ShowWindow = 2
    ShowTips = .T.
    AutoCenter = .T.
    Caption = "Any Text to image with GDIPLUSX "
    nlargestfont = 150
    nsmallestfont = 6
    cas = 0
    ygrad = .F.
    ylogo = .F.
    ndir = 0
    ypict = .F.
    ywp = .F.
    Name = "Form1"

    Add Object imgcanvas1 As imgcanvas With ;
        Anchor = 15, ;
        Stretch = 2, ;
        Height = 514, ;
        Left = 0, ;
        Top = 0, ;
        Width = 900, ;
        smoothingmode = 0, ;
        Name = "Imgcanvas1"


    Add Object edit1 As EditBox With ;
        FontSize = 10, ;
        Height = 457, ;
        Left = 156, ;
        ToolTipText = "dbClick on the editbox to close.", ;
        Top = 36, ;
        Visible = .F., ;
        Width = 481, ;
        ControlSource = "ycurs.texte", ;
        Name = "Edit1"

    Add Object cbofontname1 As cbofontname With ;
        Anchor = 768, ;
        ControlSource = "", ;
        Height = 25, ;
        Left = 25, ;
        ToolTipText = "Font", ;
        Top = 549, ;
        Width = 105, ;
        Name = "Cbofontname1"

    Add Object cbofontsize1 As cbofontsize With ;
        Anchor = 768, ;
        Left = 133, ;
        ToolTipText = "Size", ;
        Top = 549, ;
        Name = "Cbofontsize1"

    Add Object check1 As Checkbox With ;
        Top = 549, ;
        Left = 179, ;
        Height = 24, ;
        Width = 24, ;
        FontBold = .T., ;
        Anchor = 768, ;
        Alignment = 0, ;
        BackStyle = 0, ;
        Caption = "B", ;
        Style = 1, ;
        ToolTipText = "Bold", ;
        ForeColor = Rgb(255,0,0), ;
        Name = "Check1"

    Add Object check2 As Checkbox With ;
        Top = 549, ;
        Left = 206, ;
        Height = 24, ;
        Width = 24, ;
        FontBold = .T., ;
        Anchor = 768, ;
        Alignment = 0, ;
        BackStyle = 0, ;
        Caption = "I", ;
        Style = 1, ;
        ToolTipText = "Italic", ;
        ForeColor = Rgb(255,0,0), ;
        Name = "Check2"

    Add Object command1 As CommandButton With ;
        Top = 547, ;
        Left = 292, ;
        Height = 27, ;
        Width = 84, ;
        Anchor = 768, ;
        Caption = "Write", ;
        Name = "Command1"

    Add Object command2 As CommandButton With ;
        Top = 547, ;
        Left = 381, ;
        Height = 40, ;
        Width = 36, ;
        Anchor = 768, ;
        Picture = home(1)+"graphics\icons\misc\camera.ico", ;
        Caption = "", ;
        ToolTipText = "Capture  image+View", ;
        Name = "Command2"

    Add Object shape1 As Shape With ;
        Top = 549, ;
        Left = 235, ;
        Height = 24, ;
        Width = 25, ;
        Anchor = 768, ;
        ToolTipText = "Color1", ;
        BackColor = Rgb(255,0,0), ;
        Name = "Shape1"

    Add Object shape2 As Shape With ;
        Top = 549, ;
        Left = 263, ;
        Height = 24, ;
        Width = 25, ;
        Anchor = 768, ;
        ToolTipText = "Color2", ;
        BackColor = Rgb(0,255,0), ;
        Name = "Shape2"

    Add Object command3 As CommandButton With ;
        Top = 548, ;
        Left = 420, ;
        Height = 27, ;
        Width = 101, ;
        Anchor = 768, ;
        Caption = "Change text", ;
        Name = "Command3"


    Add Object combo1 As ComboBox With ;
        Anchor = 768, ;
        Height = 24, ;
        Left = 527, ;
        ToolTipText = "Borders", ;
        Top = 549, ;
        Width = 100, ;
        Name = "Combo1"

    Add Object yshape1 As Shape With ;
        Top = 549, ;
        Left = 721, ;
        Height = 24, ;
        Width = 20, ;
        Anchor = 768, ;
        ToolTipText = "Color1", ;
        Visible = .F., ;
        BackColor = Rgb(0,0,255), ;
        Name = "yShape1"

    Add Object yshape2 As Shape With ;
        Top = 549, ;
        Left = 744, ;
        Height = 24, ;
        Width = 20, ;
        Anchor = 768, ;
        ToolTipText = "Color2", ;
        Visible = .F., ;
        BackColor = Rgb(255,255,0), ;
        Name = "yShape2"

    Add Object command5 As CommandButton With ;
        Top = 548, ;
        Left = 810, ;
        Height = 27, ;
        Width = 50, ;
        Anchor = 768, ;
        Caption = "Logo", ;
        Name = "Command5"
        
     Add Object ysave As CommandButton With ;
        Top = 548, ;
        Left = 863, ;
        Height = 27, ;
        Width = 30, ;
        Anchor = 768, ;
        Caption = "Save", ;
        Name = "ysave"  

    Add Object combo2 As ComboBox With ;
        Anchor = 768, ;
        Height = 24, ;
        Left = 634, ;
        ToolTipText = "Background", ;
        Top = 548, ;
        Width = 80, ;
        Name = "Combo2"

  

    Add Object combo3 As ComboBox With ;
        Anchor = 768, ;
        Height = 24, ;
        Left = 770, ;
        ToolTipText = "Direction grad", ;
        Top = 549, ;
        Visible = .F., ;
        Width = 36, ;
        Name = "Combo3"

    Procedure yfill
        Lparameters cFontName
        oo=Thisform.cbofontsize1
        oo.Clear

        Dimension aSizes[1]
        =Afont(aSizes, cFontName)
        If aSizes[1] = -1  && The font is scalable
            lScalable = .T.
            nLen = This.nlargestfont
            nStart = This.nsmallestfont
        Else
            nLen = Alen(aSizes)
            nStart = 1
            lScalable = .F.
        Endif

        If lScalable
            For i = nStart To nLen
                oo.AddItem(Alltrim(Str(i)))
            Endfor
        Else
            For i = nStart To nLen
                oo.AddItem(Alltrim(Str(aSizes[i])))
            Endfor
        Endif
    Endproc

    Procedure Load
        Create Cursor ycurs (texte M)
        TEXT to lctext noshow
        Lorem ipsum dolor sit amet, consectetuer
        adipiscing elit. Nulla facilisi.
        Quisque dolor leo, sollicitudin a, porta vel,
         faucibus id, nunc.Suspendisse mollis nonummy
        tellus. Sed auctor pulvinar odio. Vestibulum
        ante ipsum primis in faucibus orci luctus
        et ultrices posuere cubilia Curae; Lorem
        ipsum dolor sit amet, consectetuer
        adipiscing elit. Proin lorem lacus,
        mattis et, cursus ut, viverra faucibus, purus.
         Sed feugiat mauris quis velit. Etiam
         aculis hendrerit    urna. Vivamus volutpat
        dui vel est.Sed dictum est in metus.
         Nullam facilisis aliquet turpis.
        Duis varius enim ut orci. Donec lorem ligula,
         pellentesque ac,sodales at, ornare non,
         lacus. Vivamus rutrum aliquam leo.
        ENDTEXT

        Appe Blan
        Repl texte With lctext
        *brow
    Endproc

    Procedure Init

        If  Fontmetric(1, 'MS Sans Serif', 8, '') # 13 Or ;
                fontmetric(4, 'MS Sans Serif', 8, '') # 2 Or ;
                fontmetric(6, 'MS Sans Serif', 8, '') # 5 Or ;
                fontmetric(7, 'MS Sans Serif', 8, '') # 11
            This.SetAll('fontname', 'Tahoma')
        Else
            This.SetAll('fontname','MS Sans Serif')
        Endif
        This.SetAll('fontsize',9)

        This.SetAll("mousepointer",15,"commandbutton")
        This.SetAll("Backcolor",Rgb(0,255,0),"commandbutton")
        This.imgcanvas1.Left=0
        This.imgcanvas1.Top=0
        This.imgcanvas1.Width=This.Width
        This.imgcanvas1.Height=This.Height
        This.Refresh
    Endproc

    Procedure imgcanvas1.beforedraw
        With _Screen.System.Drawing
            This.Clear(.Color.Black)

            Local logfx
            logfx=This.ogfx


            If Thisform.ygrad=.T.
                Thisform.ywp=.F.
                &&linearGradient
                color1=.Color.fromRGB(Thisform.yshape1.BackColor)
                color2=.Color.fromRGB(Thisform.yshape2.BackColor)

                pgb = .drawing2d.LinearGradientBrush.New(This.rectangle,color1,color2,Thisform.ndir)
                &&blend
                * ybl=.Drawing2d.Blend.new()
                *    ybl.Factors  =_screen.system.single.newArray(1,0,1,0,1)
                *    ybl.Positions=_Screen.System.Single.NewArray(0,0.25,0.5,0.75,1)
                *    pgb.Blend=ybl
                logfx.FillRectangle(pgb,This.rectangle)
                pgb.Dispose()
            Endi

            If Thisform.ywp=.T.
                Thisform.ygrad=.F.
                Local loBMp As xfcBitmap
                If Not Empty(Thisform.ypict)
                    Thisform.ygrad=.F.
                    loBMp=.Bitmap.fromfile(Thisform.ypict)
                    logfx.drawImage(loBMp,This.rectangle)
                Endi
            Endi

            Do Case
                Case  Thisform.cas=1
                    p=.Pen.New(.Color.gold,10)
                    logfx.drawRectangle(p,This.rectangle)
                    p=.Pen.New(.Color.red,6)
                    rc=.rectangle.New(10,10,This.Width-20,This.Height-20)
                    logfx.drawRectangle(p,rc)

                Case Thisform.cas=2
                    Local yPath As xfcGraphicsPath
                    yPath = .drawing2d.GraphicsPath.New()
                    rc=.rectangle.New(10,10,This.Width-20,This.Height-20)
                    r=30
                    x = rc.x
                    Y = rc.Y
                    xwidth   = rc.Width
                    xheight = rc.Height
                    xpath = .drawing2d.GraphicsPath.New()
                    xpath.AddArc(x, Y, r, r, 180, 90)
                    xpath.AddArc(x+xwidth - r, Y, r, r, 270, 90)
                    xpath.AddArc(x+xwidth - r, Y+xheight - r, r, r, 0, 90)
                    xpath.AddArc(x, Y+xheight - r, r, r, 90, 90)
                    xpath.CloseFigure()
                    yPath.addpath(xpath)

                    Pen = .Pen.New(.Color.gold, 16)
                    logfx.DrawPath(Pen,yPath)
                    Pen.Dispose()
                    Pen = .Pen.New(.Color.blue, 6)
                    logfx.DrawPath(Pen,yPath)
                    Pen.Dispose()

            Endcase

            Local lcStyle
            Sele ycurs
            lctext=texte
            lcStyle=""
            If Thisform.check1.Value=1
                lcStyle="B"
            Else
                lcStyle=""
            Endi
            If Thisform.check2.Value=1
                lcStyle=lcStyle+"I"
            Endi

            xfont=Thisform.cbofontname1.Value
            xsize=Thisform.cbofontsize1.Value
            If Empty(xsize)
                xsize="20"
                Thisform.cbofontsize1.Value=xsize
            Endi
            xBackcolor1=Thisform.shape1.BackColor
            xbackcolor2=Thisform.shape2.BackColor
            epaisseur=3

 

            Local loFont As xfcFont
            Do Case
                Case lcStyle == "B"
                    loStyle = .FontStyle.Bold
                Case lcStyle == "I"
                    loStyle = .FontStyle.Italic
                Case lcStyle == "BI"
                    loStyle = .FontStyle.BoldItalic
                Otherwise
                    loStyle = .FontStyle.Regular
            Endcase

            * Create a GraphicsPath object.
            Local loPath As xfcGraphicsPath
            loPath = .drawing2d.GraphicsPath.New()
            * Add the string in the chosen style.
            loPath.AddString(lctext,.FontFamily.New(xfont),loStyle,Val(xsize),.Point.New(20, 20))
            * Using a suitable pen...
            Local loPen As xfcPen
            loPen = .Pen.New(.Color.fromRGB(xBackcolor1),epaisseur)
            * Choose an appropriate smoothing mode for the border.
            This.ogfx.smoothingmode = .drawing2d.smoothingmode.AntiAlias
            * Draw around the outline of the path
            This.ogfx.DrawPath(loPen, loPath)
            * Redraw the original text
            This.ogfx.FillPath(.SolidBrush.New(.Color.fromRGB(xbackcolor2)), loPath)

            If Not Empty(Thisform.ylogo)
                Local loFox As xfcBitmap
                loFox=.Bitmap.fromfile(Thisform.ylogo)
                loFox.makeTransparent(.Color.white)
                loThumbnail = loFox.GetThumbnailImage(60,60)
                rc=.rectangle.New(This.Width-loThumbnail.Width-20,21,loThumbnail.Width,loThumbnail.Height)
                logfx.drawImage(loThumbnail,rc)
                p=.Pen.New(.Color.white,3)
                logfx.drawRectangle(p,rc)
                p.Dispose()
            Endi

        Endwith
    Endproc

    Procedure ysave.Click
        Local m.lcdest
        m.lcdest=m.yrep+Sys(2015)+".png"
        Thisform.imgcanvas1.obmp.Save(m.lcdest,_Screen.System.Drawing.imaging.imageformat.png)
        Messagebox(m.lcdest+"....saved!",0+32+4096,"",800)
    Endproc

    Procedure edit1.DblClick
        This.Visible=.F.
        Thisform.command3.Caption="Change text"
    Endproc

    Procedure edit1.GotFocus
        Set Curs On
    Endproc

    Procedure edit1.LostFocus
        Set Curs Off
        Thisform.command1.Click
    Endproc

    Procedure edit1.RightClick
        This.Value=_Cliptext
    Endproc

    Procedure cbofontname1.Click
        Thisform.yfill(This.Value)

        This.Parent.command1.Click
    Endproc

   Procedure cbofontname1.Init
        DoDefault()
        This.Value=[Arialk]
        try
        Thisform.yfill(This.Value)
        catch
        endtry
    Endproc

    Procedure cbofontsize1.Click
        This.Parent.command1.Click
    Endproc

    Procedure check1.Click
        This.Parent.command1.Click
    Endproc

    Procedure check2.Click
        This.Parent.command1.Click
    Endproc

    Procedure command1.Click
        Thisform.imgcanvas1.Draw()
    Endproc

    Procedure command2.Click
        Thisform.imgcanvas1.obmp.toClipboard()
        Run/n3 mspaint
        Inkey(2)
        loShell=Createobject("wscript.shell")
        loShell.sendKeys("^{v}")
    Endproc

    Procedure shape1.Click
        This.BackColor=Getcolor()
        This.Parent.command1.Click
    Endproc

    Procedure shape2.Click
        This.BackColor=Getcolor()
        This.Parent.command1.Click
    Endproc

    Procedure command3.Click
        Do Case
            Case This.Caption="Change text"
                This.Caption="Close editbox"
                Thisform.edit1.ZOrder(0)
                Thisform.edit1.Visible=.T.

            Case This.Caption="Close editbox"
                This.Caption="Change text"
                Thisform.edit1.Visible=.F.
        Endcase
    Endproc

    Procedure combo1.Click
        Do Case
            Case This.Value=1
                Thisform.cas=1
            Case This.Value=2
                Thisform.cas=2
        Endcase

        Thisform.imgcanvas1.Draw
        Retu
    Endproc

    Procedure combo1.Init
        This.AddItem("Rectangle border")
        This.AddItem("RoundRect.border")
        This.Style=2
        This.ListIndex=1
        This.Value=1
    Endproc

    Procedure yshape1.Click
        This.BackColor=Getcolor()
        Thisform.imgcanvas1.Draw
    Endproc


    Procedure yshape2.Click
        This.BackColor=Getcolor()
        Thisform.imgcanvas1.Draw
    Endproc


    Procedure command5.Click
        Thisform.ylogo=Getpict()
        If Not Empty(Thisform.ylogo)
            Thisform.imgcanvas1.Draw
        Endi
    Endproc

    Procedure combo2.Click
        Do Case
            Case This.Value= 1
                Thisform.ygrad=.T.
                This.Parent.yshape1.Visible=.T.
                This.Parent.yshape2.Visible=.T.
                This.Parent.combo3.Visible=.T.
                Thisform.ywp=.F.


            Case This.Value= 2
                Thisform.ygrad=.F.
                Thisform.ywp=.F.
                This.Parent.yshape1.Visible=.F.
                This.Parent.yshape2.Visible=.F.
                This.Parent.combo3.Visible=.F.

            Case This.Value=3
                Thisform.ywp=.T.
                Thisform.ygrad=.F.
                This.Parent.yshape1.Visible=.F.
                This.Parent.yshape2.Visible=.F.
                This.Parent.combo3.Visible=.F.
                Thisform.ypict=Getpict()

        Endcase

        Thisform.imgcanvas1.Draw
    Endproc

    Procedure combo2.Init
        This.AddItem("Background grad")
        This.AddItem("NO Background")
        This.AddItem("picture")
        This.Style=2
        This.Value=1
        This.ListIndex=1
    Endproc

    Procedure combo3.Click
        Thisform.ndir=This.Value
        If Thisform.ygrad=.T.
            Thisform.imgcanvas1.Draw
        Endi
    Endproc

    Procedure combo3.Init
        This.AddItem("0")
        This.AddItem("1")
        This.AddItem("2")
        This.Style=2
        This.ListIndex=1
        This.Value=1
    Endproc

    Procedure Destroy
        Clea Events
    Endproc

Enddefine
*


*End code

 

Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
Drawing texts with gdiplusX
To be informed of the latest articles, subscribe:
Comment on this post