// This code is part of GrapeCity Documents for Imaging samples.
// Copyright (c) GrapeCity, Inc. All rights reserved.
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using GrapeCity.Documents.Drawing;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Imaging;
using GrapeCity.Documents.Html;

namespace GcImagingWeb.Samples
    // This sample uses the same code as in the HelloWorld sample
    // to create an image with the "Hello, World!" text, but in addition
    // adds the GrapeCity logo copied from the GrapeCity home page
    // using GcHtml.
    // Please see notes in comments at the top of HelloWorldHtml
    // sample code for details on adding GcHtml to your projects.
    public class GcLogoHtml
        public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
            // The GrapeCity home page:
            var uri = new Uri("https://www.grapecity.com/");
            // The coordinates of the GrapeCity logo on the home page:
            var logoRc = new RectangleF(5, 0, 180, 120);

            // Create the "Hello, World!" image like in the HelloWorld sample:
            var blue = Color.FromArgb(unchecked((int)0xFF2e4884));
            var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, true, dpi, dpi);
            using (var g = bmp.CreateGraphics(blue))
                var rc = new RectangleF(0, 0, pixelSize.Width, pixelSize.Height);
                var b = new RadialGradientBrush(Color.White, blue, new PointF(0.5f, 0.5f), true);
                g.FillRectangle(rc, b);
                var tf = new TextFormat
                    Font = Font.FromFile(Path.Combine("Resources", "Fonts", "timesbd.ttf")),
                    FontSize = 64,
                    ForeColor = Color.OrangeRed,
                g.DrawString("Hello, World!", tf, rc, TextAlignment.Center, ParagraphAlignment.Center, false);

                // Copy and paste the logo from the GrapeCity home page onto the image, scaled x2:
                var fmt = new HtmlToImageFormat(false)
                    Clip = logoRc,
                    Scale = 2
                g.DrawHtml(uri, pixelSize.Width - logoRc.Width * fmt.Scale, 0, fmt, out SizeF s);
            return bmp;