'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.Collections.GenericImportsGrapeCity.Documents.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.TextImports GCTEXT = GrapeCity.Documents.TextImports GCDRAW = GrapeCity.Documents.Drawing '' Renders Arabic text using a columnar layout.'' See also MultiLang and JapaneseColumns.PublicClassArabicTextConsttext = "العربية أكبر لغات المجموعة السامية من حيث عدد المتحدثين، وإحدى أكثر اللغات انتشارًا في العالم، يتحدثها أكثر من 422 مليون نسمة،1 ويتوزع متحدثوها في المنطقة المعروفة باسم الوطن العربي، بالإضافة إلى العديد من المناطق الأخرى المجاورة كالأحواز وتركيا وتشاد ومالي والسنغالوارتيرياوللغة العربية أهمية قصوى لدى أتباع الديانة الإسلامية، فهي لغة مصدري التشريع الأساسيين في الإسلام: القرآن، والأحاديث النبوية المروية عن النبي محمد، ولا تتم الصلاة في الإسلام (وعبادات أخرى) إلا بإتقان بعض من كلمات هذه اللغة. والعربية هي أيضًا لغة طقسية رئيسية لدى عدد من الكنائس المسيحية في العالم العربي، كما كتبت بها الكثير من أهم الأعمال الدينية والفكرية اليهودية في العصور الوسطى. وأثّر انتشار الإسلام، وتأسيسه دولًا، أرتفعت مكانة اللغة العربية، وأصبحت لغة السياسة والعلم والأدب لقرون طويلة في الأراضي التي حكمها المسلمون، وأثرت العربية، تأثيرًا مباشرًا أو غير مباشر على كثير من اللغات الأخرى في العالم الإسلامي، كالتركية والفارسية والأرديةوالالبانية واللغات الأفريقية الاخرى واللغات الأوروبية مثل الروسية والإنجليزية والفرنسية والأسبانية والايطالية والألمانية.كما انها تدرس بشكل رسمى او غير رسمى في الدول الاسلامية والدول الأفريقية المحادية للوطن العربى." FunctionCreatePDF(ByVal stream AsStream) AsInteger Using reds AsGCDRAW.Image = GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "reds.jpg")), firth AsGCDRAW.Image = GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "firth.jpg")), purples AsGCDRAW.Image = GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "purples.jpg"))Dim fnt AsGCTEXT.FontDim fpath = Path.Combine("Resources", "Fonts", "times.ttf")IfFile.Exists(fpath) Then fnt = GCTEXT.Font.FromFile(fpath)Else fnt = FontCollection.SystemFonts.FindFamilyName("Times New Roman")EndIfDim ia = NewImageAlign(ImageAlignHorz.Left, ImageAlignVert.Top, True, True, True, False, False)Dim doc = NewGcPdfDocument() '' The TextLayout that will hold and render the text:Dim tl = NewTextLayout(72) With { .FirstLineIndent = 18, .ParagraphSpacing = 6, .TextAlignment = TextAlignment.Justified, .RightToLeft = True }Dim tf = NewTextFormat() With {.Font = fnt, .FontSize = 12}'' Repeat test text to fill a few pages:For i = 1To12 tl.Append(text, tf) tl.AppendLine()Next '' Layout text in 3 columns: '' (The logic/code in this sample is identical to JapaneseColumnsConstNCOLS = 3Dim margin = 36.0FDim gap = 18.0FDim page = doc.NewPage() page.Landscape = TrueDim colWid = (page.Size.Width - margin * 2 - gap * (NCOLS - 1)) / NCOLS tl.MaxWidth = page.Size.Width tl.MaxHeight = page.Size.Height tl.MarginTop = margin tl.MarginBottom = margin tl.MarginRight = margin tl.MarginLeft = margin + (colWid + gap) * (NCOLS - 1)'' We can specify arbitrary rectangles for the text to flow around.'' In this case, we add 3 areas to draw some images: tl.ObjectRects = NewList(OfObjectRect)() From {NewObjectRect(page.Size.Width - margin - 240, margin, 240, 240),NewObjectRect(margin + 100, margin + 60, 133, 100),NewObjectRect(margin, page.Size.Height - margin - 300, 300, 300) }'' Convert object rects to image areas, adjust to provide nice looking padding:Dim rReds = tl.ObjectRects(0).ToRectangleF() rReds.Inflate(-4, -3)Dim rFirth = tl.ObjectRects(1).ToRectangleF() rFirth.Inflate(-4, -3)Dim rPurples = tl.ObjectRects(2).ToRectangleF() rPurples.Inflate(-4, -3) page.Graphics.DrawImage(reds, rReds, Nothing, ia) page.Graphics.DrawImage(firth, rFirth, Nothing, ia) page.Graphics.DrawImage(purples, rPurples, Nothing, ia) '' THE call: it calculates the glyphs needed to draw the text, and lays it out: tl.PerformLayout(True) Dim done = False'' Loop while there is still text to render:WhileNot doneFor col = 1ToNCOLS Dim nextcol = If(col < NCOLS, col, 0)'' TextSplitOptions tell TextLayout.Split() how to layout the remaining text.'' In this case we advance from column to column by updating top and bottom margins:Dim tso = NewTextSplitOptions(tl) With { .RestMarginRight = margin + (colWid + gap) * nextcol, .RestMarginLeft = margin + (colWid + gap) * (NCOLS - 1 - nextcol) }Dim rest AsTextLayout = NothingDim split = tl.Split(tso, rest) page.Graphics.DrawTextLayout(tl, PointF.Empty)If split <> SplitResult.SplitThen done = TrueExitForEndIf tl = restNextIfNot done Then page = doc.NewPage() page.Landscape = True'' We only want to render images on the first page, so clear ObjectRects:IfNot tl.ObjectRectsIsNothingThen tl.ObjectRects = Nothing'' We need to redo the layout, but no need to recalculate the glyphs: tl.PerformLayout(False)EndIfEndIfEndWhile'''' Done: doc.Save(stream)Return doc.Pages.CountEndUsingEndFunctionEndClass