TateChuYoko.vb
  1. ''
  2. '' This code is part of Document Solutions for PDF demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports System.Text.RegularExpressions
  8. Imports GrapeCity.Documents.Drawing
  9. Imports GrapeCity.Documents.Pdf
  10. Imports GrapeCity.Documents.Text
  11. Imports GCTEXT = GrapeCity.Documents.Text
  12. Imports GCDRAW = GrapeCity.Documents.Drawing
  13.  
  14. '' This sample demonstrates how to render short upright Latin text jr numbers
  15. '' in a block of vertical text. This is used in Chinese, Japanese and
  16. '' Korean vertical text. In CSS this is referred to using the Japanese
  17. '' name 縦中横 (tate chu yoko). To achieve this in GcGraphics,
  18. '' the TextFormat.UprightInVerticalText property should be set.
  19. '' A number of other properties on TextLayout and TextFormat
  20. '' allow you to fine-tune the behavior, as shown in this sample.
  21. Public Class TateChuYoko
  22. Sub CreatePDF(ByVal stream As Stream)
  23. Dim doc = New GcPdfDocument()
  24. Dim page = doc.NewPage()
  25. Dim g = page.Graphics
  26.  
  27. Dim rc = Util.AddNote(
  28. "Vertical text often includes short runs of horizontal numbers or Latin text. " +
  29. "In CSS this is referred to using the Japanese name 縦中横 (tate chu yoko). " +
  30. "It occurs in Chinese, Japanese and Korean vertical text. " +
  31. "We support this by providing TextFormat.UprightInVerticalText and a few " +
  32. "related properties on TextLayout and TextFormat.",
  33. page)
  34.  
  35. Dim fntJp = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "YuGothM.ttc"))
  36. Dim fntLat = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "MyriadPro-Cond.otf"))
  37. Dim hiliteFore = Color.DarkSlateBlue
  38. Dim hiliteBack = Color.FromArgb(&HFFFFFF99)
  39.  
  40. Dim tl = g.CreateTextLayout()
  41.  
  42. '' Set text flow and other layout properties:
  43. tl.FlowDirection = FlowDirection.VerticalRightToLeft
  44. tl.MaxWidth = page.Size.Width
  45. tl.MaxHeight = page.Size.Height
  46. tl.MarginAll = 72
  47. tl.MarginTop = rc.Bottom + 36
  48. tl.ParagraphSpacing = 12
  49. tl.LineSpacingScaleFactor = 1.4F
  50.  
  51. '' g.FillRectangle(
  52. '' New RectangleF(tl.MarginLeft, tl.MarginTop, tl.MaxWidth.Value - tl.MarginLeft - tl.MarginRight, tl.MaxHeight.Value - tl.MarginTop - tl.MarginBottom),
  53. '' Color.AliceBlue)
  54.  
  55. '' Text format for upright text (short Latin words or numbers)
  56. '' (GlyphWidths turns on corresponding font features, but makes a difference
  57. '' only of those features are present in the font):
  58. Dim fUpright = New TextFormat() With
  59. {
  60. .Font = fntLat,
  61. .FontSize = 14,
  62. .UprightInVerticalText = True,
  63. .GlyphWidths = GlyphWidths.QuarterWidths,
  64. .TextRunAsCluster = True
  65. }
  66.  
  67. '' Text format for vertical Japanese and sideways Latin text:
  68. Dim fVertical = New TextFormat(fUpright) With
  69. {
  70. .Font = fntJp,
  71. .UprightInVerticalText = False,
  72. .GlyphWidths = GlyphWidths.Default,
  73. .TextRunAsCluster = False
  74. }
  75.  
  76. '' Make sure runs of sideways text do not affect vertical spacing:
  77. fVertical.UseVerticalLineGapForSideways = True
  78.  
  79. '' Two additional text formants for highlighted headers:
  80. Dim fUpHdr = New TextFormat(fUpright) With
  81. {
  82. .ForeColor = hiliteFore,
  83. .BackColor = hiliteBack
  84. }
  85. Dim fVertHdr = New TextFormat(fVertical) With
  86. {
  87. .ForeColor = hiliteFore,
  88. .BackColor = hiliteBack
  89. }
  90.  
  91. tl.Append("PDF", fUpright)
  92. tl.Append("ファイルをコードから", fVertical)
  93. tl.Append("API", fUpright)
  94. tl.Append("を利用することで操作できます。クロスプラットフォーム環境で動作するアプリケーションの開発を支援する", fVertical)
  95. tl.Append("API", fUpright)
  96. tl.Append("ライブラリです。", fVertical)
  97.  
  98. '' Smaller font size for the rest of the text:
  99. fUpright.FontSize -= 2
  100. fVertical.FontSize -= 2
  101.  
  102. '' 1:
  103. tl.AppendParagraphBreak()
  104. tl.Append("PDF", fUpHdr)
  105. tl.Append("用の包括的な", fVertHdr)
  106. tl.Append("API", fUpHdr)
  107.  
  108. tl.AppendSoftBreak()
  109. tl.Append("PDF", fUpright)
  110. tl.Append("バージョン「", fVertical)
  111. tl.Append("1.7", fUpright)
  112. tl.Append("」に準拠した", fVertical)
  113. tl.Append("API", fUpright)
  114. tl.Append("を提供し、レイアウトや機能を損なうことなく、豊富な機能を備えた", fVertical)
  115. tl.Append("PDF", fUpright)
  116. tl.Append("文書を生成、編集、保存できます。", fVertical)
  117.  
  118. '' 2:
  119. tl.AppendParagraphBreak()
  120. tl.Append("完全なテキスト描画", fVertHdr)
  121.  
  122. tl.AppendSoftBreak()
  123. tl.Append("PDF", fUpright)
  124. tl.Append("文書にテキストの描画情報が保持されます。テキストと段落の書式、特殊文字、複数の言語、縦書き、テキスト角度などが保持さるので、完全な形でテキスト描画を再現できます。", fVertical)
  125.  
  126. '' 3:
  127. tl.AppendParagraphBreak()
  128. tl.Append(".NET Standard 2.0 準拠", fVertHdr)
  129.  
  130. tl.AppendSoftBreak()
  131. tl.Append(".NET Core、.NET Framework、Xamarinで動作するアプリケーションを開発できます。Windows、macOS、Linuxなどクロスプラットフォーム環境で動作可能です。", fVertical)
  132.  
  133. '' 4:
  134. tl.AppendParagraphBreak()
  135. tl.Append("100", fUpHdr)
  136. tl.Append("を超える", fVertHdr)
  137. tl.Append("PDF", fUpHdr)
  138. tl.Append("操作機能", fVertHdr)
  139.  
  140. tl.AppendSoftBreak()
  141. tl.Append("ページの追加や削除、ページサイズ、向きの変更だけでなく、ファイルの圧縮、", fVertical)
  142. tl.Append("Web", fUpright)
  143. tl.Append("に最適化した", fVertical)
  144. tl.Append("PDF", fUpright)
  145. tl.Append("の生成など高度な機能も", fVertical)
  146. tl.Append("API", fUpright)
  147. tl.Append("操作で実現します。また、署名からセキュリティ機能まで様々な機能を含んだ", fVertical)
  148. tl.Append("PDF", fUpright)
  149. tl.Append("フォームを生成可能です。", fVertical)
  150.  
  151. '' 5:
  152. tl.AppendParagraphBreak()
  153. tl.Append("高速、軽量アーキテクチャ", fVertHdr)
  154.  
  155. tl.AppendSoftBreak()
  156. tl.Append("軽量", fVertical)
  157. tl.Append("API", fUpright)
  158. tl.Append("アーキテクチャでメモリと時間を節約できます。", fVertical)
  159. tl.AppendSoftBreak()
  160. tl.Append("また、他の生成用ツールに依存せずドキュメントを生成可能です。", fVertical)
  161.  
  162. '' 6:
  163. tl.AppendParagraphBreak()
  164. tl.Append("クラウドアプリケーション展開", fVertHdr)
  165. tl.Append("", fUpHdr)
  166.  
  167. tl.AppendSoftBreak()
  168. tl.Append("Azure、AWSなどのサービスに配置するクラウドアプリケーションの開発で利用可能です。仮想マシン、コンテナ、サーバーレスなどの方法で配置できます。", fVertical)
  169.  
  170. tl.PerformLayout(True)
  171. g.DrawTextLayout(tl, PointF.Empty)
  172.  
  173. '' Done
  174. doc.Save(stream)
  175. End Sub
  176. End Class
  177.