XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

DRAWTEXT Arabic Problem! VB.NET

Last post 7/29/2009 4:28 PM by legalize. 5 replies.
  • 7/23/2009 5:16 AM

    DRAWTEXT Arabic Problem! VB.NET

    I am having some problems rendering text in my program. I wrote an independent program to illustrate the problem. For some reason when using Direct3d.Font.Drawtext method with Arabic characters it comes out really wierd.

    For example when I try the following:

    Dim testFont As System.Drawing.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 178, False)
    Dim Font2_ As Direct3D.Font = New Direct3D.Font(device, testFont)
    Font2_.DrawText(Nothing, "مرجع شامل", New System.Drawing.Rectangle(3, 2, 338, 40), DrawTextFormat.RightToLeftReading, Color.Black)

    It'll come out in reverse and doubled. Ie. "This Example" will come out as "ThissihT ExampleelpmaxE"

    Another strange thing I've noticed is that for some reason reducing the font size below to 10.4 will get rid of the doubling up. Please try the following code to see what I mean:

           device.BeginScene() 'all drawings after this line

            Dim workingFont As System.Drawing.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.4F)
            Dim buggedFont As System.Drawing.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.5F)

            Dim Font_ As Direct3D.Font = New Direct3D.Font(device, workingFont)
            Dim Font2_ As Direct3D.Font = New Direct3D.Font(device, buggedFont)
            Dim Font3_ = New Direct3D.Font(device, 0, 0, FontWeight.Normal, 1, False, CharacterSet.Default, Precision.String, FontQuality.ClearTypeNatural, PitchAndFamily.DefaultPitch Or PitchAndFamily.FamilyDoNotCare, "Arabic")

            Font_.DrawText(Nothing, "اما اق ", 0, 0, Color.White)   'Appears different in editor but for some reason cant post it like that here. The arabic should be the second parameter
            Font2_.DrawText(Nothing, "اما اق", 0, 15, Color.White) 'Appears different in editor but for some reason cant post it like that here. The arabic should be the second parameter
            Font3_.DrawText(Nothing, "اما اق", RECT, DrawTextFormat.RightToLeftReading, Color.White)

            device.EndScene() 'all drawings before this line

            device.Present()


    All 3 draw texts have the same string being passed into it yet all three print different characters.

    Any help will be appreciated!

    The entire code
    -----------------------------------
         
    Imports Microsoft.DirectX
    Imports Microsoft.DirectX.Direct3D



    Public Class Form1
        Private device As Direct3D.Device

        Private RECT As New System.Drawing.Rectangle(0, 30, 338, 40)

        Public Sub Initialize()
            Dim present As PresentParameters = New PresentParameters
            present.Windowed = True 'we?ll draw on a window
            present.SwapEffect = SwapEffect.Discard 'discuss later
            device = New Direct3D.Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, present)
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True) 'Do not draw form?s background\

            Initialize()
        End Sub

        Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            device.BeginScene() 'all drawings after this line

            Dim workingFont As System.Drawing.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.4F)
            Dim buggedFont As System.Drawing.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.5F)

            Dim Font_ As Direct3D.Font = New Direct3D.Font(device, workingFont)
            Dim Font2_ As Direct3D.Font = New Direct3D.Font(device, buggedFont)
            Dim Font3_ = New Direct3D.Font(device, 0, 0, FontWeight.Normal, 1, False, CharacterSet.Default, Precision.String, FontQuality.ClearTypeNatural, PitchAndFamily.DefaultPitch Or PitchAndFamily.FamilyDoNotCare, "Arabic")

            Font_.DrawText(Nothing, "اما اق ", 0, 0, Color.White)
            Font2_.DrawText(Nothing, "اما اق", 0, 15, Color.White)
            Font3_.DrawText(Nothing, "اما اق", RECT, DrawTextFormat.RightToLeftReading, Color.White)

            device.EndScene() 'all drawings before this line

            device.Present()
            Me.Invalidate() 'redraw
        End Sub
    End Class

    A link to someone with the same problem, dont understand the solution -

    http://groups.google.com/group/microsoft.public.vb.directx/browse_thread/thread/57b639607568ce7a/1f48515ab7cb60a9?lnk=gst&q=arabic#1f48515ab7cb60a9

  • 7/23/2009 2:18 PM In reply to

    Re: DRAWTEXT Arabic Problem! VB.NET

    Try using SlimDX instead of managed DirectX. Managed DirectX is dead.

  • 7/27/2009 12:52 AM In reply to

    Re: DRAWTEXT Arabic Problem! VB.NET

    Before I make the journey to SlimDX. Does what this person say have any merit?

    "CD3DFont included in the sample framework doesnt support all fonts.
    you need to use ID3DXFont for that. and I also thought the source to
    CD3DFont discussses this. "

    And if it does, in terms of VB code, how can i switch to using ID3DxFont instead of CD3Dfont?
  • 7/28/2009 10:38 PM In reply to

    Re: DRAWTEXT Arabic Problem! VB.NET

    Yes, CD3DFont is written to support what the samples need and they didn't need arabic font rendering, so they most likely simply fail when attempting to render those fonts. (Or any right-to-left font rendering.)

    ID3DXFont is designed to support any font you can create with it through Windows. However, earlier versions of D3DX had bugs in the ID3DXFont implementation which were subsequently fixed. Managed DirectX uses a really old version of D3DX and won't ever get the bug fixes that were put into later versions of D3DX. SlimDX uses the current D3DX and gets the benefits of the bug fixes in the underlying native libraries. Its quite possible that if you just switch from Managed DirectX to SlimDX that your font problems will disappear.

  • 7/29/2009 3:02 AM In reply to

    Re: DRAWTEXT Arabic Problem! VB.NET

    Hi legalize you have been very helpful. I am not very familiar with VB libraries or the .net framework to be honest. So what you are saying, "Managed DirectX" is what my code currently uses? And is the standard which comes bundled in the .net framework? The only/easiest way for me to be able to use the ID3DXFont I will have to use SlimDX? Thanks again.
  • 7/29/2009 4:28 PM In reply to

    Re: DRAWTEXT Arabic Problem! VB.NET

    In your project, if you have references to Microsoft.DirectX.(something) then you are using Managed DirectX. Managed DirectX is deprecated and hasn't been updated for several years. Microsoft does not recommend using Managed DirectX. Microsoft recommends you write your own interop layer (only for the brave) or use another interop layer like SlimDX. I recommend SlimDX. With SlimDX you add a reference to the SlimDX assemblies instead of Managed DirectX assemblies.
Page 1 of 1 (6 items) Previous Next