Results 1 to 13 of 13

Thread: [RESOLVED] Text Renderer Class For Arabic Script Languages

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Resolved [RESOLVED] Text Renderer Class For Arabic Script Languages

    By default .Net Toolstrip control not render the text for RightToLeft languages correctly, I written a class to do so. All is well else after drawing graphics all the menus of toolstrip which are containing "&" not render correctly. Any help will be appreciated.

    Name:  error.png
Views: 957
Size:  16.5 KB

    Here is the class.

    PHP Code:
    Namespace UrduTextRendrer
        
    Public Class UrduTextRendrer
            Inherits ToolStripProfessionalRenderer
            
    Protected Overrides Sub OnRenderItemText(ByVal e As ToolStripItemTextRenderEventArgs)
                
    Dim sf As New StringFormat()
                If (
    e.TextFormat And TextFormatFlags.RightToLeft) <> 0 Then
                    sf
    .FormatFlags StringFormatFlags.DirectionRightToLeft
                End 
    If
                
    Using brush = New SolidBrush(e.TextColor)
                    
    e.Graphics.DrawString(e.Texte.TextFontbrush, New RectangleF(e.TextRectangle.Locatione.TextRectangle.Size), sf)
                
    End Using
            End Sub
        End 
    Class
    End Namespace 

    Usage
    PHP Code:
    ToolStripManager.Renderer = New UrduTextRendrer.UrduTextRendrer 
    Last edited by hackerspk; Nov 11th, 2012 at 02:00 AM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Text Renderer Class For Arabic Script Languages

    Any help guys

  3. #3
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Text Renderer Class For Arabic Script Languages

    By default .Net Toolstrip control not render the text for RightToLeft languages correctly,
    I cannot confirm that, i can show Arabic menu with built-in MenuStrip without any problem?

    I think you have to change your system local from control panel> region



  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Text Renderer Class For Arabic Script Languages

    It works great if you have Windows 7 +, But on windows xp if Asian languages are not installed then text will not shown correctly, if simply while rendering the text we change the string format flags it will work as good as on Windows 7. But you can see while i render the text it works but all the shortcuts and & symbols are not in correct format. I want to fix this issue

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Text Renderer Class For Arabic Script Languages

    Any one else have some idea please?

  6. #6
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Text Renderer Class For Arabic Script Languages

    Is your whole problem the ampersand sign ? If so then why not simply not use it. I don't know too much about foreign glyphs but I wouldn't expect Arabic to have an ampersand.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  7. #7
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Text Renderer Class For Arabic Script Languages

    You may remove the ampersand from the text, it is dirty solution until you find another one.

    Code:
    Namespace UrduTextRendrer
        Public Class UrduTextRendrer
            Inherits ToolStripProfessionalRenderer
            Protected Overrides Sub OnRenderItemText(ByVal e As ToolStripItemTextRenderEventArgs)
                Dim sf As New StringFormat
                If (e.TextFormat And TextFormatFlags.RightToLeft) <> 0 Then
                    sf.FormatFlags = StringFormatFlags.DirectionRightToLeft
                End If
    
                e.Text = e.Text.Replace("&"c, String.Empty) ' Remove the ampersand from the text
    
                Using brush = New SolidBrush(Color.Red) 'e.TextColor)
                    e.Graphics.DrawString(e.Text, e.TextFont, brush, New RectangleF(e.TextRectangle.Location, e.TextRectangle.Size), sf)
                End Using
            End Sub
        End Class
    End Namespace



  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Text Renderer Class For Arabic Script Languages

    Quote Originally Posted by 4x2y View Post
    You may remove the ampersand from the text, it is dirty solution until you find another one.

    Code:
    Namespace UrduTextRendrer
        Public Class UrduTextRendrer
            Inherits ToolStripProfessionalRenderer
            Protected Overrides Sub OnRenderItemText(ByVal e As ToolStripItemTextRenderEventArgs)
                Dim sf As New StringFormat
                If (e.TextFormat And TextFormatFlags.RightToLeft) <> 0 Then
                    sf.FormatFlags = StringFormatFlags.DirectionRightToLeft
                End If
    
                e.Text = e.Text.Replace("&"c, String.Empty) ' Remove the ampersand from the text
    
                Using brush = New SolidBrush(Color.Red) 'e.TextColor)
                    e.Graphics.DrawString(e.Text, e.TextFont, brush, New RectangleF(e.TextRectangle.Location, e.TextRectangle.Size), sf)
                End Using
            End Sub
        End Class
    End Namespace
    i thought of that but there is one problem more all the shortcut keys also turn to left so how to adjust these keys?

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Text Renderer Class For Arabic Script Languages

    I'm still not convinced by the whole premise that "by default .Net Toolstrip control not render the text for RightToLeft languages correctly"! What does that actually mean?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  10. #10
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Text Renderer Class For Arabic Script Languages

    Yay! Another double post to add to the collection!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  11. #11
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Text Renderer Class For Arabic Script Languages

    Quote Originally Posted by dunfiddlin View Post
    Yay! Another double post to add to the collection!
    Even if the page takes a while to change, it doesn't mean that the forum didn't acknowledge the post. You can avoid double posting by keeping that in mind. It took a while to get used to but its practically instinct now...at least for me.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Text Renderer Class For Arabic Script Languages

    Quote Originally Posted by dunfiddlin View Post
    I'm still not convinced by the whole premise that "by default .Net Toolstrip control not render the text for RightToLeft languages correctly"! What does that actually mean?
    Windows Vista, 7,8 have good Unicode support when these windows renders Arabic script languages, there is no error. But windows xp if east asian languages are not installed it cannot able to render Arabic script correctly. See picture.
    Name:  error.png
Views: 985
Size:  22.8 KB
    Some of the .net controls supports "UseCompatibleTextRendering". when it is set to true then Windows XP is also render the text as correctly as Windows 7. But toolstrip control has no UseCompatibleTextRendering property. If we render the text using this below method there is no problem with text. But there are some other errors like "&" symbols and shortcuts.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Text Renderer Class For Arabic Script Languages

    Ok problem is resolved by Mick Doherty

    PHP Code:
    Namespace UrduTextRendrer
        
    Public Class UrduTextRendrer
            Inherits ToolStripProfessionalRenderer
            
    Protected Overrides Sub OnRenderItemText(ByVal e As ToolStripItemTextRenderEventArgs)
                
    Dim sf As New StringFormat()

                
    Dim rtl As Boolean = (e.TextFormat And TextFormatFlags.RightToLeft) = TextFormatFlags.RightToLeft

                
    If rtl Then
                    sf
    .FormatFlags StringFormatFlags.DirectionRightToLeft

                    
    If (e.TextFormat TextFormatFlags.RightThen
                        e
    .TextFormat -= TextFormatFlags.Right
                    
    Else
                        
    e.TextFormat += TextFormatFlags.Right
                    End 
    If

                
    End If

                If (
    e.TextFormat And TextFormatFlags.Right) = TextFormatFlags.Right Then
                    sf
    .Alignment StringAlignment.Far
                End 
    If

                If (
    e.TextFormat And TextFormatFlags.HidePrefix) = TextFormatFlags.HidePrefix Then
                    sf
    .HotkeyPrefix Drawing.Text.HotkeyPrefix.Hide
                
    Else
                    
    sf.HotkeyPrefix Drawing.Text.HotkeyPrefix.Show
                End 
    If

                
    Using brush = New SolidBrush(e.TextColor)
                    
    e.Graphics.DrawString(e.Texte.TextFontbrushe.TextRectanglesf)
                
    End Using

            End Sub
        End 
    Class
    End Namespace 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width