'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.LinqImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.DrawingImports GCTEXT = GrapeCity.Documents.TextImports GCDRAW = GrapeCity.Documents.Drawing PublicClassAllBlendModesPublicFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()Dim page = doc.NewPage()Dim g = page.Graphics Dim iorchid = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "orchid.jpg"))Dim ispectr = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "spectrum-pastel-500x500.png")) ConstmarginAsInteger = 36ConstNCOLSAsInteger = 4Dim w = CInt((page.Size.Width - margin * 2) / NCOLS)Dim h = (iorchid.Height * w) \ iorchid.Width ' Text layout for captions:Dim tl = g.CreateTextLayout() tl.DefaultFormat.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSansMono-Regular.ttf")) tl.DefaultFormat.FontSize = 12 tl.ParagraphAlignment = ParagraphAlignment.Center tl.TextAlignment = TextAlignment.Center tl.MaxWidth = w tl.MaxHeight = h tl.MarginTop = h - g.MeasureString("QWERTY", tl.DefaultFormat).Height * 1.4F Dim row AsInteger = 0Dim col AsInteger = 0Dim dy AsInteger = 0Dim x AsInteger = 0Dim y AsInteger = 0Dim r AsRectangleF = NothingDim rc AsRectangleF = NothingDim blendMode AsBlendMode = BlendMode.NormalDim iback AsGCDRAW.Image = NothingDim ifore AsGCDRAW.Image = Nothing ' Render all blending modes in a grid:Dim modes = System.Enum.GetValues(GetType(BlendMode))For i AsInteger = 0To1 row = 0 col = 0If i = 0Then iback = ispectr ifore = iorchidDim trc1 = Util.AddNote("Below are tiles drawn by composing two images (a spectrum and an orchid) using the " &"different blend modes supported by DsPdf. " &"First the spectrum image is drawn normally, then it is overlaid by the orchid image " &"drawn in a supported blend mode. The blend mode name is shown below each tile." & vbLf &"Tiles on the second page are composed of the same images but drawn in reverse order: " &"the orchid is drawn normally, the spectrum is blended with it using the different modes." & vbLf &"Note that the current blend mode affects not only images but any drawing on a GcGraphics. " &"The blend mode names on the 2nd page illustrate this.", page) dy = CInt(Fix(trc1.Bottom))Else iback = iorchid ifore = ispectr page = doc.Pages.Add() g = page.Graphics dy = 0EndIfForEach mode In modes blendMode = CType(mode, BlendMode)IfNot g.IsBlendModeSupported(blendMode) ThenContinueForEndIf x = margin + w * col y = margin + h * row + dy r = NewRectangleF(x, y, w, h) g.BlendMode = BlendMode.Normal g.DrawImage(iback, r, Nothing, ImageAlign.StretchImage) g.BlendMode = blendMode g.DrawImage(ifore, r, Nothing, ImageAlign.StretchImage) g.BlendMode = BlendMode.Normal ' Caption: tl.Clear() tl.Append(blendMode.ToString()) tl.PerformLayout(True) rc = tl.ContentRectangle rc.Offset(x, y) rc.Inflate(4, 2) g.FillRectangle(rc, Color.White) g.DrawTextLayout(tl, NewPointF(x, y)) col += 1If col = NCOLSThen col = 0 row += 1EndIfNextNext' Text blends: page = doc.Pages(1) g = page.GraphicsDim trc = Util.AddNote("Below are supported blend mode names rendered into rectangles using the corresponding blend mode. " &"Each rectangle is first filled by the spectrum image using BlendMode.Normal, " &"then black and white texts are drawn using the current blend mode, " &"finally the same spectrum image is drawn using BlendMode.Difference to black out the background. " &"Names prefixed with 'B:' are drawn in black, " &"while names prefixed with 'W:' are drawn in white. " &"Most combinations yield rather colorful results, but for some the results are invisible.", page,NewRectangleF(margin, margin + h * row + 12, page.Bounds.Width - margin * 2, 0)) Dim yoff = CInt(Fix(trc.Bottom)) + 12 tl.DefaultFormat.FontBold = True tl.DefaultFormat.FontSize = 16 h = CInt(Fix(g.MeasureString("QWERTY", tl.DefaultFormat).Height * 1.4F)) * 2 tl.MaxWidth = w tl.MaxHeight = h tl.MarginTop = (h - h / 1.4F) / 2 tl.DefaultFormat.ForeColor = Color.BlackDim tfWhite = NewTextFormat(tl.DefaultFormat) With {.ForeColor = Color.White} row = 0 col = 0ForEach mode In modes blendMode = CType(mode, BlendMode)IfNot g.IsBlendModeSupported(blendMode) ThenContinueForEndIf x = margin + w * col y = yoff + h * row r = NewRectangleF(x, y, w, h) ' Draw spectrum image normally: g.BlendMode = BlendMode.Normal g.DrawImage(ispectr, r, Nothing, ImageAlign.StretchImage)' Draw blend mode name using the current blend mode: tl.Clear() tl.AppendLine($"B: {blendMode}") tl.Append($"W: {blendMode}", tfWhite) tl.PerformLayout(True) rc = tl.ContentRectangle rc.Offset(x, y) rc.Inflate(4, 2)' Current blend mode: g.BlendMode = blendMode g.DrawTextLayout(tl, NewPointF(x, y))' Draw spectrum image again using BlendMode.Difference' to produce (mostly) colorful text on black background: g.BlendMode = BlendMode.Difference g.DrawImage(ispectr, r, Nothing, ImageAlign.StretchImage)' Draw a rectangle to mark the current area: g.BlendMode = BlendMode.Normal g.DrawRectangle(r, Color.Gray) col += 1If col = NCOLSThen col = 0 row += 1EndIfNext' Done: doc.Save(stream)Return doc.Pages.CountEndFunctionEndClass