GoodsReturnForm.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 GrapeCity.Documents.Common
  8. Imports GrapeCity.Documents.Drawing
  9. Imports GrapeCity.Documents.Pdf
  10. Imports GrapeCity.Documents.Text
  11. Imports GrapeCity.Documents.Pdf.Annotations
  12. Imports GrapeCity.Documents.Pdf.AcroForms
  13. Imports GCTEXT = GrapeCity.Documents.Text
  14. Imports GCDRAW = GrapeCity.Documents.Drawing
  15.  
  16. '' Creates a "Goods return or exchange form" AcroForm with multiple input fields And a complex layout.
  17. Public Class GoodsReturnForm
  18. '' Page margins:
  19. Const MarginLeft = 32.0F
  20. Const MarginTop = 32.0F
  21. Const MarginRight = 32.0F
  22. Const MarginBottom = 32.0F
  23. ''
  24. Const TableCaptionHeight = 20.0F
  25. ReadOnly TableSampleHeight As Single = Textbox.Height
  26. Const SmallTextVOff As Single = -0.5F
  27. '' Section delimiting line:
  28. Dim CaptionLineThickness As Single = 2.5F
  29. '' Struct to hold a text style:
  30. Private Structure TextStyle
  31. Public Property Font As GCTEXT.Font
  32. Public Property FontSize As Single
  33. Public Property ForeColor As Color
  34. Public Property GlyphAdvanceFactor As Single
  35. End Structure
  36. '' Various styles used throughout the form:
  37. Shared TsTitle As TextStyle = New TextStyle() With {
  38. .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "SitkaB.ttc")),
  39. .FontSize = 30,
  40. .ForeColor = Color.FromArgb(&HFF, &H3B, &H5C, &HAA),
  41. .GlyphAdvanceFactor = 0.93F
  42. }
  43. Shared TsCaption As TextStyle = New TextStyle() With {
  44. .Font = TsTitle.Font,
  45. .FontSize = 14,
  46. .ForeColor = Color.FromArgb(&HFF, &H3B, &H5C, &HAA),
  47. .GlyphAdvanceFactor = 0.93F
  48. }
  49. Shared TsBold As TextStyle = New TextStyle() With {
  50. .Font = GrapeCity.Documents.Text.Font.FromFile(Path.Combine("Resources", "Fonts", "arialbd.ttf")),
  51. .FontSize = 9,
  52. .ForeColor = Color.Black,
  53. .GlyphAdvanceFactor = 1
  54. }
  55. Shared TsNormal As TextStyle = New TextStyle() With {
  56. .Font = GrapeCity.Documents.Text.Font.FromFile(Path.Combine("Resources", "Fonts", "arial.ttf")),
  57. .FontSize = 8.0F,
  58. .ForeColor = Color.Black,
  59. .GlyphAdvanceFactor = 0.922F
  60. }
  61. Shared TsSmall As TextStyle = New TextStyle() With {
  62. .Font = TsNormal.Font,
  63. .FontSize = 5,
  64. .ForeColor = Color.FromArgb(&HF, &HF, &HF),
  65. .GlyphAdvanceFactor = 1.1F
  66. }
  67. '' Input field styles:
  68. Private Structure Textbox
  69. Public Shared Property Font As GCTEXT.Font = TsNormal.Font
  70. Public Shared Property FontSize As Single = 12
  71. Public Shared Property Height As Single
  72. Public Shared Property BaselineOffset As Single
  73. Public Shared Property LabelSpacing As Single = 2
  74. End Structure
  75. Private Structure Checkbox
  76. Public Shared Font As GCTEXT.Font = TsNormal.Font
  77. Public Shared FontSize As Single = TsNormal.FontSize - 2
  78. Public Shared Height As Single
  79. Public Shared BaselineOffset As Single
  80. Public Shared LabelSpacing As Single = 3
  81. End Structure
  82. '' The document being created:
  83. Private _doc As GcPdfDocument
  84. '' Insertion point:
  85. Private _ip As PointF = New PointF(MarginLeft, MarginTop)
  86. '' If non-null, DrawText use this to align text to last baseline:
  87. Private _lastBaselineOffset As Single? = Nothing
  88. '' Shortcuts to current values:
  89. Private ReadOnly Property CurrPageIdx As Integer
  90. Get
  91. Return _doc.Pages.Count - 1
  92. End Get
  93. End Property
  94. Private ReadOnly Property CurrPage As Page
  95. Get
  96. Return _doc.Pages(CurrPageIdx)
  97. End Get
  98. End Property
  99.  
  100. Private ReadOnly Property CurrGraphics As GcGraphics
  101. Get
  102. Return CurrPage.Graphics
  103. End Get
  104. End Property
  105. '' Static ctor:
  106. Shared Sub New()
  107. '' Init Textbox:
  108. Dim tl = New TextLayout(72)
  109. tl.Append("Qwerty")
  110. tl.DefaultFormat.Font = Textbox.Font
  111. tl.DefaultFormat.FontSize = Textbox.FontSize
  112. tl.PerformLayout(True)
  113. Textbox.Height = tl.ContentHeight
  114. Textbox.BaselineOffset = tl.Lines(0).GlyphRuns(0).BaselineOffset
  115. '' Init Checkbox:
  116. tl.Clear()
  117. tl.Append("Qwerty")
  118. tl.DefaultFormat.Font = Checkbox.Font
  119. tl.DefaultFormat.FontSize = Checkbox.FontSize
  120. tl.PerformLayout(True)
  121. Checkbox.Height = tl.ContentHeight
  122. Checkbox.BaselineOffset = tl.Lines(0).GlyphRuns(0).BaselineOffset
  123. End Sub
  124. '' The main entry point:
  125. Function CreatePDF(ByVal stream As Stream) As Integer
  126. Acme()
  127. _doc.Save(stream)
  128. Return _doc.Pages.Count
  129. End Function
  130. '' Sets or advances the insertion point vertically:
  131. Private Sub SetY(ByVal abs As Single?, ByVal offset As Single?)
  132. If (abs.HasValue) Then
  133. _ip.Y = abs.Value
  134. End If
  135. If (offset.HasValue) Then
  136. _ip.Y += offset.Value
  137. End If
  138. _lastBaselineOffset = Nothing
  139. End Sub
  140. '' Creates the PDF form:
  141. Private Sub Acme()
  142. _doc = New GcPdfDocument()
  143. _doc.NewPage()
  144. Dim pageWidth = CurrPage.Size.Width
  145.  
  146. '' Main caption:
  147. SetY(Nothing, -2)
  148. Dim cr = DrawText("ACME Inc.", TsTitle)
  149. SetY(Nothing, _lastBaselineOffset - CaptionLineThickness / 2)
  150. DrawGreenLine(MarginLeft, cr.Left - CaptionLineThickness)
  151. DrawGreenLine(cr.Right + CaptionLineThickness, pageWidth - MarginRight)
  152.  
  153. '' 'return and exchange form':
  154. SetY(cr.Bottom, 10)
  155. cr = DrawText("Return and Exchange Form", TsCaption)
  156.  
  157. SetY(Nothing, CaptionLineThickness + 14)
  158. cr = DrawText("Please type in the appropriate information below, then print this form.", TsBold)
  159. _ip.X = pageWidth - 150
  160. cr = DrawText("Have Any Questions?", TsBold)
  161.  
  162. SetY(Nothing, 10)
  163. _ip.X = MarginLeft
  164. cr = DrawText("(Or you may print the form and complete it by hand.)", TsNormal)
  165. _ip.X = pageWidth - 150
  166. cr = DrawText("Please call us at 800-123-4567.", TsNormal)
  167.  
  168. '' Step 1 - line 1:
  169. SetY(Nothing, 18)
  170. _ip.X = MarginLeft
  171. cr = DrawText("Step 1", TsCaption)
  172. _ip.X = cr.Right + 10
  173. cr = DrawText("Original Order #", TsBold)
  174. _ip.X = cr.Right + 4
  175. cr = DrawText("(if available):", TsNormal)
  176. _ip.X = cr.Right + Textbox.LabelSpacing
  177. cr = DrawTextbox(120)
  178. _ip.X = cr.Right + 6
  179. cr = DrawText("Estimated Order Date:", TsBold)
  180. _ip.X = cr.Right + Textbox.LabelSpacing
  181. cr = DrawTextbox(pageWidth - MarginRight - _ip.X)
  182. SetY(Nothing, 17)
  183. DrawGreenLine()
  184. '' Step 1 - line 2:
  185. SetY(Nothing, 10)
  186. _ip.X = MarginLeft
  187. cr = DrawText("Originally Purchased by:", TsBold)
  188. _ip.X = cr.Right + 20
  189. cr = DrawCheckbox("Address Change")
  190. Dim col1right = pageWidth / 2 - 10
  191. Dim col2left = col1right + 20
  192. _ip.X = col2left
  193. cr = DrawText("Send Refund or Exchange to:", TsBold)
  194. _ip.X = cr.Right + 2
  195. cr = DrawText("(If different from left)", TsNormal)
  196. '' Step 1 - line 3:
  197. SetY(cr.Bottom, 10)
  198. _ip.X = MarginLeft
  199. cr = DrawText("Name:", TsNormal)
  200. _ip.X = cr.Right + Textbox.LabelSpacing
  201. cr = DrawTextbox(col1right - _ip.X)
  202. _ip.X = col2left
  203. cr = DrawText("Name:", TsNormal)
  204. _ip.X = cr.Right + Textbox.LabelSpacing
  205. cr = DrawTextbox(pageWidth - MarginRight - _ip.X)
  206. '' Step 1 - line 4:
  207. SetY(cr.Bottom, 4 + 4)
  208. _ip.X = MarginLeft
  209. cr = DrawText("Address:", TsNormal)
  210. _ip.X = cr.Right + Textbox.LabelSpacing
  211. cr = DrawTextbox(col1right - _ip.X)
  212. _ip.X = col2left
  213. cr = DrawText("Address:", TsNormal)
  214. _ip.X = cr.Right + Textbox.LabelSpacing
  215. cr = DrawTextbox(pageWidth - MarginRight - _ip.X)
  216. '' Step 1 - line 5:
  217. SetY(cr.Bottom, 4 + 0.5F)
  218. _ip.X = MarginLeft
  219. cr = DrawTextbox(col1right - _ip.X)
  220. _ip.X = col2left
  221. cr = DrawTextbox(pageWidth - MarginRight - _ip.X)
  222. '' Step 1 - line 6 (city state zip):
  223. SetY(cr.Bottom, 4 + 0.5F)
  224. _ip.X = MarginLeft
  225. cr = DrawTextbox(160)
  226. _ip.X = cr.Right + 4
  227. Dim oState = _ip.X - MarginLeft
  228. cr = DrawTextbox(40)
  229. _ip.X = cr.Right + 4
  230. Dim oZip = _ip.X - MarginLeft
  231. cr = DrawTextbox(col1right - _ip.X)
  232. ''
  233. _ip.X = col2left
  234. cr = DrawTextbox(160)
  235. _ip.X = cr.Right + 4
  236. cr = DrawTextbox(40)
  237. _ip.X = cr.Right + 4
  238. cr = DrawTextbox(pageWidth - MarginRight - _ip.X)
  239. '' small text
  240. SetY(cr.Bottom, SmallTextVOff)
  241. _ip.X = MarginLeft
  242. cr = DrawText("(City)", TsSmall)
  243. _ip.X = MarginLeft + oState
  244. cr = DrawText("(State)", TsSmall)
  245. _ip.X = MarginLeft + oZip
  246. cr = DrawText("(Zip)", TsSmall)
  247. ''
  248. _ip.X = col2left
  249. cr = DrawText("(City)", TsSmall)
  250. _ip.X = col2left + oState
  251. cr = DrawText("(State)", TsSmall)
  252. _ip.X = col2left + oZip
  253. cr = DrawText("(Zip)", TsSmall)
  254. '' Step 1 - line 7 (daytime):
  255. SetY(cr.Bottom, 4 - 0.5F)
  256. _ip.X = MarginLeft
  257. cr = DrawText("Phone: (", TsNormal)
  258. _ip.X = cr.Right
  259. cr = DrawTextbox(30)
  260. _ip.X = cr.Right
  261. cr = DrawText(")", TsNormal)
  262. _ip.X += 3
  263. cr = DrawTextbox(80)
  264. Dim oDay = cr.Left - MarginLeft + 10
  265. '' (evening)
  266. _ip.X = cr.Right + 3
  267. cr = DrawText("(", TsNormal)
  268. _ip.X = cr.Right
  269. cr = DrawTextbox(30)
  270. _ip.X = cr.Right
  271. cr = DrawText(")", TsNormal)
  272. _ip.X += 3
  273. cr = DrawTextbox(col1right - _ip.X)
  274. Dim oEve = cr.Left - MarginLeft + 10
  275. ''
  276. _ip.X = col2left
  277. cr = DrawText("Phone: (", TsNormal)
  278. _ip.X = cr.Right
  279. cr = DrawTextbox(30)
  280. _ip.X = cr.Right
  281. cr = DrawText(")", TsNormal)
  282. _ip.X += 3
  283. cr = DrawTextbox(80)
  284. '' (evening)
  285. _ip.X = cr.Right + 3
  286. cr = DrawText("(", TsNormal)
  287. _ip.X = cr.Right
  288. cr = DrawTextbox(30)
  289. _ip.X = cr.Right
  290. cr = DrawText(")", TsNormal)
  291. _ip.X += 3
  292. cr = DrawTextbox(pageWidth - MarginRight - _ip.X)
  293. '' small text
  294. SetY(cr.Bottom, SmallTextVOff)
  295. _ip.X = MarginLeft + oDay
  296. cr = DrawText("(Daytime)", TsSmall)
  297. _ip.X = MarginLeft + oEve
  298. cr = DrawText("(Evening)", TsSmall)
  299. _ip.X = col2left + oDay
  300. cr = DrawText("(Daytime)", TsSmall)
  301. _ip.X = col2left + oEve
  302. cr = DrawText("(Evening)", TsSmall)
  303. '' Step 1 - email
  304. SetY(cr.Bottom, 4 - 0.5F)
  305. _ip.X = MarginLeft
  306. cr = DrawText("Email Address:", TsNormal)
  307. _ip.X = cr.Right + Textbox.LabelSpacing
  308. cr = DrawTextbox(col1right - _ip.X)
  309. _ip.X = col2left
  310. cr = DrawText("Email Address:", TsNormal)
  311. _ip.X = cr.Right + Textbox.LabelSpacing
  312. cr = DrawTextbox(pageWidth - MarginRight - _ip.X)
  313. '' Options:
  314. SetY(Nothing, 16)
  315. _ip.X = MarginLeft
  316. cr = DrawText("Please select one of the following options:", TsBold)
  317. SetY(cr.Bottom, 2)
  318. cr = DrawCheckbox("Exchange for another item(s).")
  319. SetY(cr.Bottom, 2)
  320. cr = DrawCheckbox("Send me an ACME Gift Card for the amount of the refund.")
  321. SetY(cr.Bottom, 2)
  322. cr = DrawCheckbox("Reimburse my original method of payment. " +
  323. "(Gift recipients who select this option will receive a merchandise only gift card.)")
  324.  
  325. '' Step 2
  326. SetY(Nothing, 18)
  327. _ip.X = MarginLeft
  328. cr = DrawText("Step 2–Returns", TsCaption)
  329. _ip.X = cr.Right + 10
  330. cr = DrawText("In the form below please indicate the item(s) you are returning, " +
  331. "including a reason code.", TsNormal)
  332. SetY(Nothing, 17)
  333. DrawGreenLine()
  334. SetY(Nothing, 10)
  335. cr = DrawReturnsTable()
  336. SetY(cr.Bottom, 10)
  337. cr = DrawReasonCodes()
  338.  
  339. '' Step 3
  340. SetY(Nothing, 25)
  341. _ip.X = MarginLeft
  342. cr = DrawText("Step 3–Exchanges", TsCaption)
  343. _ip.X = cr.Right + 10
  344. SetY(Nothing, -5)
  345. cr = DrawText(
  346. "For the fastest service, call Customer Service at 800-123-4567 to request a QuickExchange " +
  347. "or place a new order online or by phone. We'll ship your new item right away. " +
  348. "Note: If you use our QuickExchange option, you do not need to fill out Step 3.",
  349. TsNormal)
  350. SetY(Nothing, 22)
  351. DrawGreenLine()
  352.  
  353. SetY(Nothing, 10)
  354. cr = DrawExchangesTable()
  355.  
  356. '' Step 4
  357. SetY(Nothing, 18)
  358. _ip.X = MarginLeft
  359. cr = DrawText("Step 4", TsCaption)
  360. SetY(Nothing, 17)
  361. DrawGreenLine()
  362.  
  363. SetY(Nothing, 10)
  364. _ip.X = MarginLeft
  365. Dim oCc = col2left - 30
  366. cr = DrawText("Method of Payment:", TsBold)
  367. _ip.X = oCc
  368. cr = DrawText("Credit Card Information:", TsBold)
  369. SetY(cr.Bottom, 2)
  370. _ip.X = MarginLeft
  371. cr = DrawText("If the total of your exchange or new order exceeds the value of your" + vbCrLf +
  372. "return, please provide a method of payment. (Select one)", TsNormal)
  373. _ip.X = oCc
  374. cr = DrawCheckbox("ACME® Visa®")
  375. Dim oCcOff = 90
  376. _ip.X += oCcOff
  377. cr = DrawCheckbox("MasterCard®")
  378. _ip.X += oCcOff
  379. cr = DrawCheckbox("JCB Cardâ„¢")
  380.  
  381. SetY(cr.Bottom, 2)
  382. _ip.X = oCc
  383. cr = DrawCheckbox("VISA")
  384. _ip.X += oCcOff
  385. cr = DrawCheckbox("American Express")
  386. _ip.X += oCcOff
  387. cr = DrawCheckbox("Discover®/Novus® Cards")
  388.  
  389. SetY(cr.Bottom, 4)
  390. _ip.X = MarginLeft
  391. cr = DrawCheckbox("Credit Card")
  392. SetY(cr.Bottom, 2)
  393. cr = DrawCheckbox("Check or Money Order enclosed")
  394. SetY(cr.Bottom, 2)
  395. cr = DrawCheckbox("Gift Card, Gift Certificate or ACME Visa coupon dollars." + vbCrLf +
  396. "Enter # below (for Gift Cards, please include PIN).")
  397. _ip.X = oCc
  398. cr = DrawText("Card Number:", TsNormal)
  399. _ip.X = cr.Right + Textbox.LabelSpacing
  400. cr = DrawTextbox(180)
  401. _ip.X = cr.Right + 4
  402. cr = DrawTextbox(pageWidth - MarginRight - _ip.X)
  403. '' small text
  404. SetY(cr.Bottom, SmallTextVOff)
  405. _ip.X = cr.Left
  406. cr = DrawText("Exp. Date (MM/YY)", TsSmall)
  407.  
  408. SetY(cr.Bottom, 10)
  409. _ip.X = MarginLeft
  410. cr = DrawText("Number:", TsNormal)
  411. _ip.X = cr.Right + Textbox.LabelSpacing
  412. cr = DrawTextbox(140)
  413. Dim tbBottom = cr.Bottom
  414. _ip.X = cr.Right + 4
  415. cr = DrawTextbox(60)
  416. Dim oPin = cr.Left
  417. _ip.X = oCc
  418. cr = DrawText("Signature:", TsNormal)
  419. CurrGraphics.DrawLine(New PointF(cr.Right, cr.Bottom),
  420. New PointF(pageWidth - MarginRight, cr.Bottom), Color.Black, 0.5F)
  421. '' small text
  422. SetY(tbBottom, SmallTextVOff)
  423. _ip.X = oPin
  424. cr = DrawText("PIN", TsSmall)
  425. End Sub
  426.  
  427. Private Sub DrawGreenLine(Optional ByVal from_ As Single? = Nothing, Optional ByVal to_ As Single? = Nothing)
  428. Dim page = CurrPage
  429. If Not from_.HasValue Then
  430. from_ = MarginLeft
  431. End If
  432. If Not to_.HasValue Then
  433. to_ = page.Size.Width - MarginRight
  434. End If
  435. Dim g = page.Graphics
  436. Dim pen = New GCDRAW.Pen(TsTitle.ForeColor, CaptionLineThickness)
  437. g.DrawLine(New PointF(from_.Value, _ip.Y), New PointF(to_.Value, _ip.Y), pen)
  438. End Sub
  439.  
  440. Private Function DrawText(ByVal text As String, ByVal ts As TextStyle) As RectangleF
  441. Dim page = CurrPage
  442. Dim tl = page.Graphics.CreateTextLayout()
  443. tl.MaxWidth = page.Size.Width - MarginRight - _ip.X
  444. If ts.FontSize = TsTitle.FontSize Then
  445. tl.TextAlignment = TextAlignment.Center
  446. End If
  447. tl.DefaultFormat.Font = ts.Font
  448. tl.DefaultFormat.FontSize = ts.FontSize
  449. tl.DefaultFormat.GlyphAdvanceFactor = ts.GlyphAdvanceFactor
  450. tl.DefaultFormat.ForeColor = ts.ForeColor
  451. tl.Append(text)
  452. tl.PerformLayout(True)
  453. Dim line = tl.Lines(tl.Lines.Count - 1)
  454. Dim run = line.GlyphRuns(0)
  455. Dim baselineOffset = run.BaselineOffset
  456. Dim p = If(_lastBaselineOffset.HasValue, New PointF(_ip.X, _ip.Y + _lastBaselineOffset.Value - baselineOffset), _ip)
  457. page.Graphics.DrawTextLayout(tl, p)
  458. If Not _lastBaselineOffset.HasValue Then
  459. _lastBaselineOffset = baselineOffset ''#34 within one 'line', keep imports the first offset
  460. End If
  461. Return New RectangleF(_ip.X + tl.ContentX, _ip.Y + tl.ContentY, tl.ContentWidth, tl.ContentHeight)
  462. End Function
  463.  
  464. Private Function DrawTextbox(ByVal width As Single, Optional ByVal inTable As Boolean = False) As RectangleF
  465. Dim fld = New TextField()
  466. fld.Widget.Page = CurrPage
  467. Dim p = If(_lastBaselineOffset.HasValue, New PointF(_ip.X, _ip.Y + _lastBaselineOffset.Value - Textbox.BaselineOffset), _ip)
  468. fld.Widget.Rect = New RectangleF(p.X, p.Y, width, Textbox.Height)
  469. If inTable Then
  470. fld.Widget.Border = Nothing
  471. Else
  472. fld.Widget.Border.Style = BorderStyle.Underline
  473. End If
  474. fld.Widget.DefaultAppearance.Font = Textbox.Font
  475. fld.Widget.DefaultAppearance.FontSize = Textbox.FontSize
  476. _doc.AcroForm.Fields.Add(fld)
  477. If Not _lastBaselineOffset.HasValue Then
  478. _lastBaselineOffset = Textbox.BaselineOffset
  479. End If
  480. Return fld.Widget.Rect
  481. End Function
  482.  
  483. Private Function DrawCheckbox(ByVal text As String) As RectangleF
  484. Dim fld = New CheckBoxField()
  485. fld.Widget.Page = CurrPage
  486. Dim p = If(_lastBaselineOffset.HasValue, New PointF(_ip.X, _ip.Y + _lastBaselineOffset.Value - Checkbox.BaselineOffset), _ip)
  487. fld.Widget.Rect = New RectangleF(p.X, p.Y, Checkbox.Height, Checkbox.Height)
  488. _doc.AcroForm.Fields.Add(fld)
  489. If Not _lastBaselineOffset.HasValue Then
  490. _lastBaselineOffset = Checkbox.BaselineOffset
  491. End If
  492. Dim pSave = _ip
  493. _ip.X = fld.Widget.Rect.Right + Checkbox.LabelSpacing
  494. Dim r = DrawText(Text, TsNormal)
  495. _ip = pSave
  496. Return New RectangleF(fld.Widget.Rect.X, r.Y, r.Right - fld.Widget.Rect.Left, r.Height)
  497. End Function
  498.  
  499. Private Function DrawReturnsTable() As RectangleF
  500. Dim widths As Single() = {
  501. 55,
  502. 60,
  503. 60,
  504. 35,
  505. 35,
  506. 200,
  507. 50,
  508. 0
  509. }
  510. Dim captions As String() = {
  511. "Reason Code",
  512. "Item #",
  513. "Color",
  514. "Size",
  515. "Quantity",
  516. "Item Name",
  517. "Pirce",
  518. "Total"
  519. }
  520. Dim samples As String() = {
  521. "23",
  522. "KK123456",
  523. "Navy",
  524. "8",
  525. "1",
  526. "Example Item Only",
  527. "59.00",
  528. "59.00"
  529. }
  530. Return DrawTable(widths, captions, samples, 4)
  531. End Function
  532.  
  533. Private Function DrawExchangesTable() As RectangleF
  534. '' This table has two special extra titles spanning two tolumns.
  535. '' To achieve this, we:
  536. '' - force the column titles in those 4 columns to print as '2nd paragraph',
  537. '' thus leaving an empty line for the span title
  538. '' - print the span titles here as a special case.
  539. Dim widths As Single() = {
  540. 50,
  541. 25,
  542. 25,
  543. 25,
  544. 25,
  545. 60,
  546. 150,
  547. 50,
  548. 40,
  549. 25,
  550. 35,
  551. 0
  552. }
  553. Dim captions As String() = {
  554. "Item",
  555. "Style",
  556. vbCrLf + "1st",
  557. vbCrLf + "2nd",
  558. "Size",
  559. "Sleeve Length" + vbCrLf + "& Inseam",
  560. "Item Name",
  561. vbCrLf + "Characters",
  562. vbCrLf + "Style",
  563. "Qty.",
  564. "Price",
  565. "Total"
  566. }
  567. Dim samples As String() = {
  568. "LH123456",
  569. "Plain",
  570. "Tan",
  571. "Olive",
  572. "8",
  573. "28",
  574. "Example Item Only",
  575. "Amanda",
  576. "Block",
  577. "1",
  578. "49.95",
  579. "49.95"
  580. }
  581.  
  582. Dim cr = DrawTable(widths, captions, samples, 4)
  583.  
  584. '' print 2 spanning titles:
  585. Dim g = CurrGraphics
  586. Dim tl = g.CreateTextLayout()
  587. tl.ParagraphAlignment = ParagraphAlignment.Near
  588. tl.TextAlignment = TextAlignment.Center
  589. tl.DefaultFormat.Font = TsNormal.Font
  590. tl.DefaultFormat.FontSize = TsNormal.FontSize
  591. tl.DefaultFormat.GlyphAdvanceFactor = TsNormal.GlyphAdvanceFactor
  592. tl.DefaultFormat.ForeColor = Color.White
  593. tl.WrapMode = WrapMode.NoWrap
  594. '' Color Choice
  595. Dim width = widths(2) + widths(3)
  596. tl.MaxWidth = width
  597. tl.Append("Color Choice")
  598. tl.PerformLayout(True)
  599. Dim pt = New PointF(cr.Left + widths(0) + widths(1), cr.Top)
  600. g.DrawTextLayout(tl, pt)
  601. Dim pen = New GCDRAW.Pen(Color.White, 0.5F)
  602. Dim pt1 = New PointF(pt.X + 0.5F, pt.Y + TableCaptionHeight / 2)
  603. Dim pt2 = New PointF(pt1.X + width, pt1.Y)
  604. g.DrawLine(pt1, pt2, pen)
  605. pt1 = New PointF(pt.X + widths(2) + 0.5F, pt.Y + TableCaptionHeight / 2)
  606. pt2 = New PointF(pt1.X, pt.Y + TableCaptionHeight)
  607. g.DrawLine(pt1, pt2, pen)
  608. pt1 = New PointF(pt.X + 0.5F, pt.Y)
  609. pt2 = New PointF(pt1.X, pt.Y + TableCaptionHeight)
  610. g.DrawLine(pt1, pt2, pen)
  611. pt1 = New PointF(pt.X + width + 0.5F, pt.Y)
  612. pt2 = New PointF(pt1.X, pt.Y + TableCaptionHeight)
  613. g.DrawLine(pt1, pt2, pen)
  614. '' Monogramming
  615. width = widths(7) + widths(8)
  616. tl.Inlines.Clear()
  617. tl.MaxWidth = width
  618. tl.Append("Monogramming")
  619. tl.PerformLayout(True)
  620. pt = New PointF(cr.Left + widths(0) + widths(1) + widths(2) + widths(3) + widths(4) + widths(5) + widths(6), cr.Top)
  621. g.DrawTextLayout(tl, pt)
  622. pt1 = New PointF(pt.X + 0.5F, pt.Y + TableCaptionHeight / 2)
  623. pt2 = New PointF(pt1.X + width, pt1.Y)
  624. g.DrawLine(pt1, pt2, pen)
  625. pt1 = New PointF(pt.X + widths(7) + 0.5F, pt.Y + TableCaptionHeight / 2)
  626. pt2 = New PointF(pt1.X, pt.Y + TableCaptionHeight)
  627. g.DrawLine(pt1, pt2, pen)
  628. pt1 = New PointF(pt.X + 0.5F, pt.Y)
  629. pt2 = New PointF(pt1.X, pt.Y + TableCaptionHeight)
  630. g.DrawLine(pt1, pt2, pen)
  631. pt1 = New PointF(pt.X + width + 0.5F, pt.Y)
  632. pt2 = New PointF(pt1.X, pt.Y + TableCaptionHeight)
  633. g.DrawLine(pt1, pt2, pen)
  634.  
  635. Return cr
  636. End Function
  637.  
  638. Private Function DrawTable(ByVal widths As Single(), ByVal captions As String(), ByVal samples As String(), ByVal rowCount As Integer) As RectangleF
  639. Debug.Assert(captions.Length = widths.Length AndAlso samples.Length = widths.Length)
  640.  
  641. Dim ipSave = _ip
  642. Dim p = New GCDRAW.Pen(Color.Black, 0.5F)
  643.  
  644. Dim g = CurrGraphics
  645. Dim tl = g.CreateTextLayout()
  646. tl.ParagraphAlignment = ParagraphAlignment.Center
  647. tl.TextAlignment = TextAlignment.Center
  648. tl.DefaultFormat.Font = TsNormal.Font
  649. tl.DefaultFormat.FontSize = TsNormal.FontSize
  650. tl.DefaultFormat.GlyphAdvanceFactor = TsNormal.GlyphAdvanceFactor
  651. tl.DefaultFormat.ForeColor = Color.White
  652. tl.WrapMode = WrapMode.NoWrap
  653. tl.MaxHeight = TableCaptionHeight
  654. Dim totW = 0F
  655. For i = 0 To widths.Length - 1
  656. If i = widths.Length - 1 Then
  657. widths(i) = CurrPage.Size.Width - MarginLeft - MarginRight - totW - 1
  658. totW += 1
  659. End If
  660. totW += widths(i)
  661. Next
  662. g.FillRectangle(New RectangleF(MarginLeft, _ip.Y, totW, TableCaptionHeight), Color.Black)
  663. Dim pt = New PointF(MarginLeft, _ip.Y)
  664. For i = 0 To widths.Length - 1
  665. tl.MaxWidth = widths(i)
  666. tl.Append(captions(i))
  667. tl.PerformLayout(True)
  668. g.DrawTextLayout(tl, pt)
  669. pt.X = pt.X + widths(i)
  670. tl.Inlines.Clear()
  671. Next
  672. tl.DefaultFormat.ForeColor = Color.Teal
  673. tl.MaxHeight = TableSampleHeight
  674. pt = New PointF(MarginLeft, _ip.Y + TableCaptionHeight)
  675. For i = 0 To widths.Length - 1
  676. tl.MaxWidth = widths(i)
  677. tl.Append(samples(i))
  678. tl.PerformLayout(True)
  679. g.DrawTextLayout(tl, pt)
  680. pt.X = pt.X + widths(i)
  681. tl.Inlines.Clear()
  682. Next
  683. SetY(_ip.Y + TableCaptionHeight + TableSampleHeight, 0.5F)
  684. For row = 0 To rowCount - 1
  685. _ip.X = MarginLeft + 1
  686. For i = 0 To widths.Length - 1
  687. Dim cr = DrawTextbox(widths(i) - 1, True)
  688. _ip.X = cr.Right + 1
  689. Next
  690. g.DrawLine(New PointF(MarginLeft, _ip.Y - 0.5F), New PointF(MarginLeft + totW, _ip.Y - 0.5F), p)
  691. SetY(Nothing, Textbox.Height + 1)
  692. Next
  693. Dim totH = TableCaptionHeight + TableSampleHeight + (Textbox.Height + 1) * rowCount
  694. _ip.X = MarginLeft + 0.5F
  695. For i = 0 To widths.Length - 2
  696. _ip.X += widths(i)
  697. g.DrawLine(New PointF(_ip.X, ipSave.Y), New PointF(_ip.X, ipSave.Y + totH), p)
  698. Next
  699.  
  700. Dim rect = New RectangleF(MarginLeft, ipSave.Y, totW, totH)
  701. g.DrawRectangle(rect, p)
  702.  
  703. Return rect
  704. End Function
  705.  
  706. Private Function DrawReasonCodes() As RectangleF
  707. Dim startX = 150.0F
  708. Dim capOff = 16.0F
  709. Dim colOff = 110.0F
  710. Dim ipSave = _ip
  711.  
  712. _ip.X = startX
  713. Dim cr = DrawText("01", TsNormal)
  714. _ip.X += capOff
  715. cr = DrawText("Unsatisfactory", TsNormal)
  716. _ip.X = startX + colOff
  717. cr = DrawText("33", TsNormal)
  718. _ip.X += capOff
  719. cr = DrawText("Did not like color", TsNormal)
  720. _ip.X = startX + colOff * 2
  721. cr = DrawText("23", TsNormal)
  722. _ip.X += capOff
  723. cr = DrawText("Ordered wrong size", TsNormal)
  724. _ip.X = startX + colOff * 3
  725. cr = DrawText("51", TsNormal)
  726. _ip.X += capOff
  727. cr = DrawText("Shipping damage", TsNormal)
  728. SetY(Nothing, TsNormal.FontSize + 2)
  729. _ip.X = startX
  730. cr = DrawText("02", TsNormal)
  731. _ip.X += capOff
  732. cr = DrawText("Defective construction", TsNormal)
  733. _ip.X = startX + colOff
  734. cr = DrawText("21", TsNormal)
  735. _ip.X += capOff
  736. cr = DrawText("Too small", TsNormal)
  737. _ip.X = startX + colOff * 2
  738. cr = DrawText("25", TsNormal)
  739. _ip.X += capOff
  740. cr = DrawText("Too short", TsNormal)
  741. _ip.X = startX + colOff * 3
  742. cr = DrawText("52", TsNormal)
  743. _ip.X += capOff
  744. cr = DrawText("Wrong item shipped", TsNormal)
  745.  
  746. _ip.X = MarginLeft + 10
  747. cr = DrawText("Reason Codes", TsBold)
  748. Dim lineX = cr.Right + 20
  749.  
  750. SetY(Nothing, TsNormal.FontSize + 2)
  751. _ip.X = startX
  752. cr = DrawText("31", TsNormal)
  753. _ip.X += capOff
  754. cr = DrawText("Did not like styling", TsNormal)
  755. _ip.X = startX + colOff
  756. cr = DrawText("22", TsNormal)
  757. _ip.X += capOff
  758. cr = DrawText("Too large", TsNormal)
  759. _ip.X = startX + colOff * 2
  760. cr = DrawText("36", TsNormal)
  761. _ip.X += capOff
  762. cr = DrawText("Too long", TsNormal)
  763.  
  764. Dim rect = New RectangleF(MarginLeft, ipSave.Y, CurrPage.Size.Width, cr.Bottom - ipSave.Y)
  765. CurrGraphics.DrawLine(lineX, rect.Top, lineX, rect.Bottom, Color.Black, 0.5F)
  766.  
  767. Return rect
  768. End Function
  769. End Class
  770.