'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.DrawingImportsGrapeCity.Documents.DrawingImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.ImagingImports GCDRAW = GrapeCity.Documents.Drawing '' This demo illustrates the results of using the GcGraphics.DrawRotatedText() method'' with different combinations of arguments.'' The DrawRotatedText() method draws text rotated within a specified rectangle'' similar to how rotated text is drawn in MS Excel cells without borders.'' See also the DrawSlantedText_0 demo.PublicClassDrawRotatedTextPrivateShareds_namesAsString() = NewString() {"Rotate Counter-clockwise","Rotate Clockwise","Vertical Stacking","Varying RotatedTextAlignment","Vertical Stacking Align","Horizontal Stacking Align" } PublicFunctionGenerateImage(ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,OptionalByVal sampleParams AsString() = Nothing) AsGcBitmap If sampleParams IsNothingThen sampleParams = GetSampleParamsList()(0)EndIf Dim bmp = NewGcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi)Using g = bmp.CreateGraphics(Color.White)'' Set up some values to manage layout:Dim margin = g.ResolutionDim gap = g.ResolutionDim w = pixelSize.Width * 0.3FDim h = w Dim q0 = NewRectangleF(margin, margin, w, h)Dim q1 = NewRectangleF(pixelSize.Width - margin - w, margin, w, h)Dim q2 = NewRectangleF(margin, margin + h + gap, w, h)Dim q3 = NewRectangleF(pixelSize.Width - margin - w, margin + h + gap, w, h) If sampleParams(0) = s_names(0) Then'' Draw text at different negative angles:Draw(g, q0, -90, False, RotatedTextAlignment.BottomLeft, TextAlignment.Leading)Draw(g, q1, -60, False, RotatedTextAlignment.BottomLeft, TextAlignment.Leading)Draw(g, q2, -45, False, RotatedTextAlignment.BottomLeft, TextAlignment.Leading)Draw(g, q3, -30, False, RotatedTextAlignment.BottomLeft, TextAlignment.Leading)ElseIf sampleParams(0) = s_names(1) Then'' Draw text at different positive angles:Draw(g, q0, -90, False, RotatedTextAlignment.TopRight, TextAlignment.Leading)Draw(g, q1, -60, False, RotatedTextAlignment.TopRight, TextAlignment.Leading)Draw(g, q2, -45, False, RotatedTextAlignment.TopRight, TextAlignment.Leading)Draw(g, q3, -30, False, RotatedTextAlignment.TopRight, TextAlignment.Leading)ElseIf sampleParams(0) = s_names(2) Then'' Draw text using different vertical stacking:Draw(g, q0, -30, True, RotatedTextAlignment.TopRight, TextAlignment.Trailing)Draw(g, q1, -30, False, RotatedTextAlignment.TopRight, TextAlignment.Trailing)Draw(g, q2, -30, False, RotatedTextAlignment.BottomLeft, TextAlignment.Leading)Draw(g, q3, -30, True, RotatedTextAlignment.BottomLeft, TextAlignment.Leading)ElseIf sampleParams(0) = s_names(3) Then'' RotatedTextAlignment affects the location of text (red) within the target rectangle (green):Draw(g, q0, -30, True, RotatedTextAlignment.TopRight, TextAlignment.Trailing)Draw(g, q1, 60, False, RotatedTextAlignment.BottomRight, TextAlignment.Trailing)Draw(g, q2, 30, True, RotatedTextAlignment.TopLeft, TextAlignment.Leading)Draw(g, q3, -60, False, RotatedTextAlignment.BottomLeft, TextAlignment.Leading)ElseIf sampleParams(0) = s_names(4) Then'' Draw vertically stacked text using different TextAlignment values:Draw(g, q0, 30, True, RotatedTextAlignment.TopLeft, TextAlignment.Leading)Draw(g, q1, 30, True, RotatedTextAlignment.TopLeft, TextAlignment.Trailing)Draw(g, q2, 30, True, RotatedTextAlignment.TopLeft, TextAlignment.Center)Draw(g, q3, 30, True, RotatedTextAlignment.TopLeft, TextAlignment.Distributed)ElseIf sampleParams(0) = s_names(5) Then'' Draw horizontally stacked text using different TextAlignment values:Draw(g, q0, -70, False, RotatedTextAlignment.BottomLeft, TextAlignment.Leading)Draw(g, q1, -70, False, RotatedTextAlignment.BottomLeft, TextAlignment.Trailing)Draw(g, q2, -70, False, RotatedTextAlignment.BottomLeft, TextAlignment.Center)Draw(g, q3, -70, False, RotatedTextAlignment.BottomLeft, TextAlignment.Distributed)EndIfEndUsingReturn bmpEndFunction PrivateSharedSubDraw(g AsGcGraphics, rect AsRectangleF, angle AsInteger, verticalStacking AsBoolean, rotatedAlign AsRotatedTextAlignment, textAlign AsTextAlignment) '' Draw a legend stating the current DrawRotatedText arguments' values:Dim tlLegend = g.CreateTextLayout() tlLegend.DefaultFormat.FontName = "Calibri" tlLegend.DefaultFormat.FontSize = 9 tlLegend.AppendLine($"Rotation angle: {angle}°") tlLegend.AppendLine($"Text alignment: {textAlign}") tlLegend.AppendLine($"Rotated text alignment: {rotatedAlign}") tlLegend.AppendLine($"Is vertical stacking: {verticalStacking}") g.DrawTextLayout(tlLegend, rect.Location) '' The target rectangle for the DrawRotatedText call:Dim d = tlLegend.ContentHeight + 12 rect.Y += d rect.Height -= d Dim tl = g.CreateTextLayout() tl.DefaultFormat.FontName = "Calibri" tl.DefaultFormat.FontSize = 12 tl.Append("The quick brown fox jumps over the lazy dog. ") tl.Append("The quick brown fox jumps over the lazy dog.") tl.TextAlignment = textAlign'' Draw rotated text: g.DrawRotatedText(tl, angle, verticalStacking, rect, rotatedAlign) '' Outline the target rectangle in green: g.DrawRectangle(rect, NewGCDRAW.Pen(Color.PaleGreen, 3))'' Outline the actual text rectangle in red:Dim tlCopy = tl.Clone(True)Dim tlRect = g.MeasureRotatedText(tlCopy, angle, verticalStacking, rect, rotatedAlign) g.DrawRectangle(tlRect, NewGCDRAW.Pen(Color.Red, 1))EndSub '' Strings are name, description, info. Rest are arbitrary strings:PublicSharedFunctionGetSampleParamsList() As List(OfString())ReturnNew List(OfString()) From {NewString() {s_names(0), "Draw rotated text at different negative angles", Nothing},NewString() {s_names(1), "Draw rotated text at different positive angles", Nothing},NewString() {s_names(2), "Draw rotated text using different vertical stacking", Nothing},NewString() {s_names(3), "Draw text using different rotated text alignments", Nothing},NewString() {s_names(4), "Draw vertically stacked text using different TextAlignment values", Nothing},NewString() {s_names(5), "Draw horizontally stacked text using different TextAlignment values", Nothing} }EndFunctionEndClass