//
// This code is part of Document Solutions for Imaging demos.
// Copyright (c) MESCIUS 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 GCTEXT = GrapeCity.Documents.Text;
using GCDRAW = GrapeCity.Documents.Drawing;
namespace DsImagingWeb.Demos
{
// This sample demonstrates the different hatch brush styles.
// Many of those styles implement MS Excel pattern styles.
public class HatchStyles
{
public GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null)
{
// HatchStyle
var hatchStyles = Enum.GetValues(typeof(HatchStyle));
int COLS = 4;
var w = pixelSize.Width / COLS;
var h = pixelSize.Height / ((hatchStyles.Length + COLS -1) / COLS);
var tf = new TextFormat
{
Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf")),
FontSize = 12,
};
var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, true, dpi, dpi);
using (var g = bmp.CreateGraphics(Color.White))
{
int row = 0, col = 0;
foreach (HatchStyle hs in hatchStyles)
{
// Hatch:
var rc = new RectangleF(col * w, row * h, w, h);
var b = new HatchBrush(hs)
{
ForeColor = Color.Black,
BackColor = Color.White
};
g.FillRectangle(rc, b);
// Caption:
var cap = hs.ToString();
var scap = g.MeasureString(cap, tf);
var rcap = new RectangleF(
rc.X + (rc.Width - scap.Width) / 2,
rc.Y + (rc.Height - scap.Height) / 2,
scap.Width, scap.Height);
rcap.Inflate(3, 2);
g.FillRectangle(rcap, Color.White);
g.DrawString(cap, tf, rcap, TextAlignment.Center, ParagraphAlignment.Center);
// Move on:
if (++col >= COLS)
{
col = 0;
++row;
}
}
}
return bmp;
}
}
}