SupportedBarcodes.vb
'' 
'' このコードは、DioDocs for PDF のサンプルの一部として提供されています。
'' Copyright (c) GrapeCity inc. All rights reserved.
'' 
imports System.IO
imports System.Drawing
imports System.Collections.Generic
imports GrapeCity.Documents.Drawing
imports GrapeCity.Documents.Pdf
imports GrapeCity.Documents.Text
imports GrapeCity.Documents.Barcode
imports GcWebCommon

'' ライブラリで出力可能なすべてのバーコードシンボルのサンプルを描画します。
Public Class SupportedBarcodes
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Dim page As Page = Nothing
        Dim g As GcGraphics = Nothing
        Const margin = 72.0F / 2
        Const pad = 4.0F
        Const gap = 10.0F
        Dim ip = New PointF(margin, margin)

        Dim newPage As Action =
            Sub()
                page = doc.NewPage()
                g = page.Graphics
                ip = New PointF(margin, margin)
            End Sub

        newPage()

        Dim tfCaption = New TextFormat() With {
                .FontName = "Yu Gothic",
                .FontSize = 12
            }
        Dim tfBarcode = New TextFormat() With {
            .Font = StandardFonts.Helvetica,
            .FontSize = 9
        }
        Dim barcode = New GcBarcode() With {
            .TextFormat = tfBarcode,
            .ScaleFactor = 1.5F
        }
        barcode.Options.CaptionPosition = BarCodeCaptionPosition.Below
        barcode.Options.SizeOptions.NarrowWideRatio = 0

        Dim drawBarcode As Action(Of CodeType, String, String) =
            Sub(ct_, txt_, txt2_)
                Dim caption = $"{ct_}:{vbCrLf}{txt_}"
                If String.IsNullOrEmpty(txt2_) Then
                    barcode.Options.GS1Composite.Type = GS1CompositeType.None
                Else
                    caption += $"{vbCrLf}Dependent CCA: {txt2_}"
                    barcode.Options.GS1Composite.Type = GS1CompositeType.CCA
                    barcode.Options.GS1Composite.Value = txt2_
                End If

                barcode.Options.CheckSumEnabled = ct_ <> CodeType.Code25intlv AndAlso ct_ <> CodeType.Code_2_of_5 AndAlso ct_ <> CodeType.Matrix_2_of_5
                Dim csize = g.MeasureString(caption, tfCaption)
                barcode.CodeType = ct_
                barcode.Text = txt_
                Dim size = g.MeasureBarcode(barcode)
                size.Height = Math.Max(size.Height, csize.Height)
                Dim border = New RectangleF(ip, New SizeF(page.Size.Width - margin * 2, size.Height + pad * 2))
                If ip.Y + border.Height > page.Size.Height - margin Then
                    newPage()
                    border = New RectangleF(ip, border.Size)
                End If
                g.DrawRectangle(border, Color.Gray)
                g.DrawString(caption, tfCaption, New PointF(border.Left + pad, border.Top + pad))
                g.DrawBarcode(barcode, New RectangleF(border.Right - size.Width - pad, border.Top + pad, size.Width, size.Height))
                ip.Y = border.Bottom + gap
            End Sub
        ''
        drawBarcode(CodeType.Ansi39, "*DIODOCS*", Nothing)
        drawBarcode(CodeType.Ansi39x, "*DioDocs*", Nothing)
        drawBarcode(CodeType.Codabar, "A12041961D", Nothing)
        drawBarcode(CodeType.Code25intlv, "1234567890", Nothing) '' Interleaved 2 of 5 (ITF)
        drawBarcode(CodeType.Code39, "*GCBARCODE*", Nothing)
        drawBarcode(CodeType.Code39x, "*DioDocs*", Nothing)
        drawBarcode(CodeType.Code49, "GrapeCity+DioDocs", Nothing)
        drawBarcode(CodeType.Code93x, "GrapeCity+DioDocs", Nothing)
        drawBarcode(CodeType.Code_93, "GCBARCODE", Nothing)
        drawBarcode(CodeType.Code_128_A, "GCPDF-2018", Nothing)
        drawBarcode(CodeType.Code_128_B, "GcPdf-2018", Nothing)
        drawBarcode(CodeType.Code_128_C, "1234567890", Nothing)
        drawBarcode(CodeType.Code_128auto, "GcPdf-2018", Nothing)
        drawBarcode(CodeType.Code_2_of_5, "1234567890", Nothing)
        drawBarcode(CodeType.DataMatrix, "GrapeCity+DioDocs", Nothing)
        drawBarcode(CodeType.QRCode, "グレープシティ DioDocs for PDF", Nothing)
        drawBarcode(CodeType.EAN_8, "1234567", Nothing)
        drawBarcode(CodeType.EAN_13, "469" + "87654" + "3210", Nothing)
        drawBarcode(CodeType.EAN128FNC1, "GrapeCity\nDioDocs", Nothing)
        drawBarcode(CodeType.IntelligentMail, "00300999999000000001", Nothing)
        drawBarcode(CodeType.JapanesePostal, "9813205", Nothing)
        drawBarcode(CodeType.PostNet, "152063949", Nothing)
        drawBarcode(CodeType.RM4SCC, "SE17PB9Z", Nothing)
        drawBarcode(CodeType.Matrix_2_of_5, "1234567890", Nothing)
        drawBarcode(CodeType.MSI, "1234567890", Nothing)
        drawBarcode(CodeType.MicroPDF417, "DioDocs", Nothing)
        drawBarcode(CodeType.Pdf417, "DioDocs", Nothing)
        drawBarcode(CodeType.RSS14, "1234567890", Nothing)
        drawBarcode(CodeType.RSS14Stacked, "1234567890", Nothing)
        drawBarcode(CodeType.RSS14Stacked, "1234567890", "12345")
        drawBarcode(CodeType.RSS14StackedOmnidirectional, "1234567890", Nothing)
        drawBarcode(CodeType.RSS14Truncated, "1234567890", Nothing)
        drawBarcode(CodeType.RSSExpanded, "12345678901234", Nothing)
        drawBarcode(CodeType.RSSExpandedStacked, "12345678901234", Nothing)
        drawBarcode(CodeType.RSSLimited, "1234567890", Nothing)
        drawBarcode(CodeType.RSSLimited, "1234567890", "12345")
        drawBarcode(CodeType.UCCEAN128, "GrapeCity+DioDocs", Nothing)
        drawBarcode(CodeType.UPC_A, "123456789012", Nothing)
        drawBarcode(CodeType.UPC_E0, "123456789012", Nothing)
        drawBarcode(CodeType.UPC_E1, "123456789012", Nothing)
        ''
        '' PDF ドキュメントを保存します。
        doc.Save(stream)
        Return doc.Pages.Count
    End Function
End Class