ArabicText.vb
  1. ''
  2. '' This code is part of Document Solutions for Imaging demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports System.Numerics
  8. Imports GrapeCity.Documents.Drawing
  9. Imports GrapeCity.Documents.Text
  10. Imports GrapeCity.Documents.Imaging
  11. Imports GCTEXT = GrapeCity.Documents.Text
  12. Imports GCDRAW = GrapeCity.Documents.Drawing
  13.  
  14. '' This sample shows how to draw Arabic text on a GcBitmap.
  15. Public Class ArabicText
  16. Function GenerateImage(
  17. ByVal pixelSize As Size,
  18. ByVal dpi As Single,
  19. ByVal opaque As Boolean,
  20. Optional ByVal sampleParams As String() = Nothing) As GcBitmap
  21.  
  22. Dim Text = "العربية أكبر لغات المجموعة السامية من حيث عدد المتحدثين، وإحدى أكثر اللغات انتشارًا في العالم، يتحدثها أكثر من 422 مليون نسمة،1 ويتوزع متحدثوها في المنطقة المعروفة باسم الوطن العربي، بالإضافة إلى العديد من المناطق الأخرى المجاورة كالأحواز وتركيا وتشاد ومالي والسنغالوارتيرياوللغة العربية أهمية قصوى لدى أتباع الديانة الإسلامية، فهي لغة مصدري التشريع الأساسيين في الإسلام: القرآن، والأحاديث النبوية المروية عن النبي محمد، ولا تتم الصلاة في الإسلام (وعبادات أخرى) إلا بإتقان بعض من كلمات هذه اللغة. والعربية هي أيضًا لغة طقسية رئيسية لدى عدد من الكنائس المسيحية في العالم العربي، كما كتبت بها الكثير من أهم الأعمال الدينية والفكرية اليهودية في العصور الوسطى. وأثّر انتشار الإسلام، وتأسيسه دولًا، أرتفعت مكانة اللغة العربية، وأصبحت لغة السياسة والعلم والأدب لقرون طويلة في الأراضي التي حكمها المسلمون، وأثرت العربية، تأثيرًا مباشرًا أو غير مباشر على كثير من اللغات الأخرى في العالم الإسلامي، كالتركية والفارسية والأرديةوالالبانية واللغات الأفريقية الاخرى واللغات الأوروبية مثل الروسية والإنجليزية والفرنسية والأسبانية والايطالية والألمانية.كما انها تدرس بشكل رسمى او غير رسمى في الدول الاسلامية والدول الأفريقية المحادية للوطن العربى."
  23. Dim ia = New ImageAlign(ImageAlignHorz.Left, ImageAlignVert.Top, True, True, False, False, False)
  24.  
  25. Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi)
  26. Using g = bmp.CreateGraphics(Color.White)
  27. g.Renderer.Multithreaded = True
  28.  
  29. Dim tl = g.CreateTextLayout()
  30. tl.FirstLineIndent = 18
  31. tl.ParagraphSpacing = 6
  32. tl.TextAlignment = TextAlignment.Justified
  33. tl.RightToLeft = True
  34. Dim fnt As GCTEXT.Font
  35. Dim fpath = Path.Combine("Resources", "Fonts", "times.ttf")
  36. If File.Exists(fpath) Then
  37. fnt = GCTEXT.Font.FromFile(fpath)
  38. Else
  39. fnt = FontCollection.SystemFonts.FindFamilyName("Times New Roman")
  40. End If
  41. Dim tf = New TextFormat() With
  42. {
  43. .Font = fnt,
  44. .FontSize = 14
  45. }
  46.  
  47. '' Repeat test text to fill a few columns
  48. For i = 0 To 3
  49. tl.Append(Text, tf)
  50. tl.AppendLine()
  51. Next
  52.  
  53. '' Layout text in 3 columns
  54. '' (The logic/code in this sample Is identical to JapaneseColumns
  55. Const NCOLS = 3
  56. Dim margin = 48.0F
  57. Dim gap = 24.0F
  58. Dim colWid = (bmp.Width - margin * 2 - gap * (NCOLS - 1)) / NCOLS
  59. tl.MaxWidth = bmp.Width
  60. tl.MaxHeight = bmp.Height
  61. tl.MarginTop = margin
  62. tl.MarginBottom = margin
  63. tl.MarginRight = margin
  64. tl.MarginLeft = margin + (colWid + gap) * (NCOLS - 1)
  65. '' We can specify arbitrary rectangles for the text to flow around.
  66. '' In this case, we add 3 areas to draw some images:
  67. Dim rect1 = New ObjectRect(bmp.Width - margin - 315, margin, 320, 320)
  68. Dim rect2 = New ObjectRect(margin + 133, margin + 80, 177, 133)
  69. Dim rect3 = New ObjectRect(margin, bmp.Height - margin - 400, 400, 385)
  70. tl.ObjectRects = New List(Of ObjectRect)() From {rect1, rect2, rect3}
  71.  
  72. '' THE call: it calculates the glyphs needed To draw the text, And lays it out:
  73. tl.PerformLayout(True)
  74.  
  75. For col = 0 To NCOLS - 1
  76. Dim nextcol = If(col < NCOLS - 1, col + 1, 0)
  77. '' TextSplitOptions tell TextLayout.Split() how to layout the remaining text.
  78. '' In this case we advance from column to column by updating top And bottom margins:
  79. Dim tso = New TextSplitOptions(tl) With
  80. {
  81. .RestMarginRight = margin + (colWid + gap) * nextcol,
  82. .RestMarginLeft = margin + (colWid + gap) * (NCOLS - 1 - nextcol)
  83. }
  84. Dim rest As TextLayout = Nothing
  85. Dim split = tl.Split(tso, rest)
  86. g.DrawTextLayout(tl, PointF.Empty)
  87. If (split <> SplitResult.Split) Then
  88. Exit For
  89. End If
  90. tl = rest
  91. Next
  92.  
  93. rect1.Height -= 5
  94. rect2.Left += 10
  95. rect3.Width -= 10
  96.  
  97. Using img = Util.ImageFromFile(Path.Combine("Resources", "Images", "reds.jpg"))
  98. g.DrawImage(img, rect1.ToRectangleF(), Nothing, ia)
  99. End Using
  100. Using img = Util.ImageFromFile(Path.Combine("Resources", "Images", "firth.jpg"))
  101. g.DrawImage(img, rect2.ToRectangleF(), Nothing, ia)
  102. End Using
  103. Using img = Util.ImageFromFile(Path.Combine("Resources", "Images", "purples.jpg"))
  104. g.DrawImage(img, rect3.ToRectangleF(), Nothing, ia)
  105. End Using
  106.  
  107. '' Draw border around the whole image
  108. g.DrawRectangle(New RectangleF(0, 0, bmp.Width, bmp.Height), Color.DarkSlateBlue, 4)
  109. End Using
  110. Return bmp
  111. End Function
  112. End Class
  113.