hOLOlu LCD

C# Kayan Yazı Denemesi
This commit is contained in:
Mustafa ÖZKAYA
2015-03-10 05:29:32 +02:00
parent 72da4dd173
commit 89e1f8d694
98 changed files with 9450 additions and 0 deletions

View File

@@ -0,0 +1,550 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace TextDesignerCSLibrary
{
public class BmpOutlineText
{
public BmpOutlineText()
{
m_pbmpResult = null;
m_pbmpMask = null;
m_pbmpShadow = null;
m_clrBkgd = Color.FromArgb(0, 255, 0);
m_clrOutline = Color.FromArgb(255,0,0);
m_clrText = Color.FromArgb(0,0,255);
m_PngOutlineText = new PngOutlineText();
m_PngShadow = new PngOutlineText();
}
public Bitmap Render(
uint nTextX,
uint nTextY,
Bitmap pbmpText,
uint nOutlineX,
uint nOutlineY,
Bitmap pbmpOutline)
{
if(pbmpText==null)
return null;
if(pbmpOutline==null)
return null;
m_pbmpResult = new Bitmap((int)(pbmpOutline.Width+nOutlineX), (int)(pbmpOutline.Height+nOutlineY), PixelFormat.Format32bppArgb);
Bitmap png = m_PngOutlineText.GetPngImage();
BitmapData bitmapDataResult = new BitmapData();
BitmapData bitmapDataText = new BitmapData();
BitmapData bitmapDataOutline = new BitmapData();
BitmapData bitmapDataPng = new BitmapData();
Rectangle rectResult = new Rectangle(0, 0, m_pbmpResult.Width, m_pbmpResult.Height );
Rectangle rectText = new Rectangle(0, 0, pbmpText.Width, pbmpText.Height );
Rectangle rectOutline = new Rectangle(0, 0, pbmpOutline.Width, pbmpOutline.Height );
Rectangle rectPng = new Rectangle(0, 0, m_pbmpMask.Width, m_pbmpMask.Height );
m_pbmpResult.LockBits(
rectResult,
ImageLockMode.WriteOnly,
PixelFormat.Format32bppArgb,
bitmapDataResult );
pbmpText.LockBits(
rectText,
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb,
bitmapDataText );
pbmpOutline.LockBits(
rectOutline,
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb,
bitmapDataOutline );
png.LockBits(
rectPng,
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb,
bitmapDataPng );
unsafe
{
uint* pixelsResult = (uint*)bitmapDataResult.Scan0;
uint* pixelsText = (uint*)bitmapDataText.Scan0;
uint* pixelsOutline = (uint*)bitmapDataOutline.Scan0;
uint* pixelsPng = (uint*)bitmapDataPng.Scan0;
if( pixelsResult==null || pixelsText==null || pixelsOutline==null || pixelsPng==null )
return null;
uint col = 0;
int strideResult = bitmapDataResult.Stride >> 2;
int strideOutline = bitmapDataOutline.Stride >> 2;
int strideText = bitmapDataText.Stride >> 2;
int stridePng = bitmapDataPng.Stride >> 2;
for(uint row = 0; row < bitmapDataResult.Height; ++row)
{
for(col = 0; col < bitmapDataResult.Width; ++col)
{
uint indexResult = (uint)(row * strideResult + col);
uint indexText = (uint)((row-nTextY)* strideText + (col-nTextX));
uint indexOutline = (uint)((row-nOutlineY) * strideOutline + (col-nOutlineX));
uint indexPng = (uint)(row * stridePng + col);
byte red = (byte)((pixelsPng[indexPng] & 0xff0000) >> 16);
byte blue = (byte)(pixelsPng[indexPng] & 0xff);
if(red>0&&blue>0)
{
uint nOutlineColor = pixelsOutline[indexOutline];
byte aOutline = (byte)((nOutlineColor & 0xff000000) >> 24);
byte rOutline = (byte)((nOutlineColor & 0xff0000) >> 16);
byte gOutline = (byte)((nOutlineColor & 0xff00) >> 8);
byte bOutline = (byte)(nOutlineColor & 0xff);
if (aOutline > 0)
{
aOutline = (byte)((red * aOutline) >> 8);
rOutline = (byte)((red * rOutline) >> 8);
gOutline = (byte)((red * gOutline) >> 8);
bOutline = (byte)((red * bOutline) >> 8);
}
else
{
rOutline = 0;
gOutline = 0;
bOutline = 0;
}
uint nTextColor = pixelsText[indexText];
byte aText = (byte)((nTextColor & 0xff000000) >> 24);
byte rText = (byte)((nTextColor & 0xff0000) >> 16);
byte gText = (byte)((nTextColor & 0xff00) >> 8);
byte bText = (byte)(nTextColor & 0xff);
if (aText > 0)
{
aText = (byte)((blue * aText) >> 8);
rText = (byte)((blue * rText) >> 8);
gText = (byte)((blue * gText) >> 8);
bText = (byte)((blue * bText) >> 8);
}
else
{
rText = 0;
gText = 0;
bText = 0;
}
if (aText > 0 && aOutline > 0)
{
pixelsResult[indexResult] = (uint)((0xff << 24) | (Clamp((uint)(rOutline + rText)) << 16) | (Clamp((uint)(gOutline + gText)) << 8) | Clamp((uint)(bOutline + bText)));
}
else if (aOutline > 0)
pixelsResult[indexResult] = (uint)((aOutline << 24) | (Clamp((uint)(rOutline + rText)) << 16) | (Clamp((uint)(gOutline + gText)) << 8) | Clamp((uint)(bOutline + bText)));
else if (aText > 0)
pixelsResult[indexResult] = (uint)((aText << 24) | (Clamp((uint)(rOutline + rText)) << 16) | (Clamp((uint)(gOutline + gText)) << 8) | Clamp((uint)(bOutline + bText)));
else
pixelsResult[indexResult] = 0;
}
else if(red>0)
{
uint nOutlineColor = pixelsOutline[indexOutline];
byte a = (byte)((nOutlineColor & 0xff000000) >> 24);
byte r = (byte)((nOutlineColor & 0xff0000) >> 16);
byte g = (byte)((nOutlineColor & 0xff00) >> 8);
byte b = (byte)(nOutlineColor & 0xff);
if (a > 0)
pixelsResult[indexResult] = (uint)((red << 24) | (r << 16) | (g << 8) | b);
else
pixelsResult[indexResult] = 0;
}
else if(blue>0)
{
uint nTextColor = pixelsText[indexText];
byte a = (byte)((nTextColor & 0xff000000) >> 24);
byte r = (byte)((nTextColor & 0xff0000) >> 16);
byte g = (byte)((nTextColor & 0xff00) >> 8);
byte b = (byte)(nTextColor & 0xff);
if (a > 0)
pixelsResult[indexResult] = (uint)((blue << 24) | (r << 16) | (g << 8) | b);
else
pixelsResult[indexResult] = 0;
}
else
{
pixelsResult[indexResult] = 0;
}
}
}
}
png.UnlockBits(
bitmapDataPng );
pbmpOutline.UnlockBits(
bitmapDataOutline );
pbmpText.UnlockBits(
bitmapDataText );
m_pbmpResult.UnlockBits(
bitmapDataResult );
return m_pbmpResult;
}
public bool DrawString(
Graphics pGraphics,
FontFamily pFontFamily,
FontStyle fontStyle,
int nfontSize,
string pszText,
Point ptDraw,
StringFormat pStrFormat,
int nThickness,
int nWidth,
int nHeight,
bool bGlow,
byte nGlowAlpha)
{
if (bGlow)
m_PngOutlineText.TextGlow(m_clrText, Color.FromArgb(nGlowAlpha, m_clrOutline.R, m_clrOutline.G, m_clrOutline.B), nThickness);
else
m_PngOutlineText.TextOutline(m_clrText, m_clrOutline, nThickness);
m_PngOutlineText.EnableReflection(false);
m_PngOutlineText.EnableShadow(false);
m_pbmpMask = new Bitmap(nWidth, nHeight, PixelFormat.Format32bppArgb);
Graphics graph = Graphics.FromImage(m_pbmpMask);
SolidBrush brush = new SolidBrush(m_clrBkgd);
graph.FillRectangle(brush, 0, 0, m_pbmpMask.Width, m_pbmpMask.Height);
m_PngOutlineText.SetPngImage(m_pbmpMask);
m_PngOutlineText.DrawString(
pGraphics,
pFontFamily,
fontStyle,
nfontSize,
pszText,
ptDraw,
pStrFormat);
return true;
}
public bool DrawString(
Graphics pGraphics,
FontFamily pFontFamily,
FontStyle fontStyle,
int nfontSize,
string pszText,
Rectangle rtDraw,
StringFormat pStrFormat,
int nThickness,
int nWidth,
int nHeight,
bool bGlow,
byte nGlowAlpha)
{
if (bGlow)
m_PngOutlineText.TextGlow(m_clrText, Color.FromArgb(nGlowAlpha, m_clrOutline.R, m_clrOutline.G, m_clrOutline.B), nThickness);
else
m_PngOutlineText.TextOutline(m_clrText, m_clrOutline, nThickness);
m_PngOutlineText.EnableReflection(false);
m_PngOutlineText.EnableShadow(false);
m_pbmpMask = new Bitmap(nWidth, nHeight, PixelFormat.Format32bppArgb);
Graphics graph = Graphics.FromImage(m_pbmpMask);
SolidBrush brush = new SolidBrush(m_clrBkgd);
graph.FillRectangle(brush, 0, 0, m_pbmpMask.Width, m_pbmpMask.Height);
m_PngOutlineText.SetPngImage(m_pbmpMask);
m_PngOutlineText.DrawString(
pGraphics,
pFontFamily,
fontStyle,
nfontSize,
pszText,
rtDraw,
pStrFormat);
return true;
}
public bool DrawString(
Graphics pGraphics,
FontFamily pFontFamily,
FontStyle fontStyle,
int nfontSize,
string pszText,
Point ptDraw,
StringFormat pStrFormat,
int nThickness,
int nWidth,
int nHeight,
bool bGlow,
byte nGlowAlpha,
bool bShadow,
Color clrShadow,
int nShadowOffsetX,
int nShadowOffsetY)
{
if (bGlow)
m_PngOutlineText.TextGlow(m_clrText, Color.FromArgb(nGlowAlpha, m_clrOutline.R, m_clrOutline.G, m_clrOutline.B), nThickness);
else
m_PngOutlineText.TextOutline(m_clrText, m_clrOutline, nThickness);
m_PngOutlineText.EnableReflection(false);
m_PngOutlineText.EnableShadow(false);
if(bShadow)
{
m_PngShadow.SetNullTextEffect();
m_PngShadow.EnableShadow(true);
m_PngShadow.Shadow(clrShadow, nThickness, new Point(nShadowOffsetX, nShadowOffsetY));
m_PngShadow.SetShadowBkgd(Color.FromArgb(0,0,0), nWidth, nHeight);
}
else
m_PngShadow.EnableShadow(false);
m_pbmpMask = new Bitmap(nWidth, nHeight, PixelFormat.Format32bppArgb);
using (Graphics graph = Graphics.FromImage(m_pbmpMask))
{
using (SolidBrush brush = new SolidBrush(m_clrBkgd))
{
graph.FillRectangle(brush, 0, 0, m_pbmpMask.Width, m_pbmpMask.Height);
}
}
m_PngOutlineText.SetPngImage(m_pbmpMask);
m_PngOutlineText.DrawString(
pGraphics,
pFontFamily,
fontStyle,
nfontSize,
pszText,
ptDraw,
pStrFormat);
if (bShadow)
{
m_pbmpShadow = new Bitmap(nWidth, nHeight, PixelFormat.Format32bppArgb);
m_PngShadow.SetPngImage(m_pbmpShadow);
m_PngShadow.DrawString(
pGraphics,
pFontFamily,
fontStyle,
nfontSize,
pszText,
ptDraw,
pStrFormat);
}
return true;
}
public bool DrawString(
Graphics pGraphics,
FontFamily pFontFamily,
FontStyle fontStyle,
int nfontSize,
string pszText,
Rectangle rtDraw,
StringFormat pStrFormat,
int nThickness,
int nWidth,
int nHeight,
bool bGlow,
byte nGlowAlpha,
bool bShadow,
Color clrShadow,
int nShadowOffsetX,
int nShadowOffsetY)
{
if (bGlow)
m_PngOutlineText.TextGlow(m_clrText, Color.FromArgb(nGlowAlpha, m_clrOutline.R, m_clrOutline.G, m_clrOutline.B), nThickness);
else
m_PngOutlineText.TextOutline(m_clrText, m_clrOutline, nThickness);
m_PngOutlineText.EnableReflection(false);
m_PngOutlineText.EnableShadow(false);
if (bShadow)
{
m_PngShadow.SetNullTextEffect();
m_PngShadow.EnableShadow(true);
m_PngShadow.Shadow(clrShadow, nThickness, new Point(nShadowOffsetX, nShadowOffsetY));
m_PngShadow.SetShadowBkgd(Color.FromArgb(0, 0, 0), nWidth, nHeight);
}
else
m_PngShadow.EnableShadow(false);
m_pbmpMask = new Bitmap(nWidth, nHeight, PixelFormat.Format32bppArgb);
using (Graphics graph = Graphics.FromImage(m_pbmpMask))
{
using (SolidBrush brush = new SolidBrush(m_clrBkgd))
{
graph.FillRectangle(brush, 0, 0, m_pbmpMask.Width, m_pbmpMask.Height);
}
}
m_PngOutlineText.SetPngImage(m_pbmpMask);
m_PngOutlineText.DrawString(
pGraphics,
pFontFamily,
fontStyle,
nfontSize,
pszText,
rtDraw,
pStrFormat);
if(bShadow)
{
m_pbmpShadow = new Bitmap(nWidth, nHeight, PixelFormat.Format32bppArgb);
m_PngShadow.SetPngImage(m_pbmpShadow);
m_PngShadow.DrawString(
pGraphics,
pFontFamily,
fontStyle,
nfontSize,
pszText,
rtDraw,
pStrFormat);
}
return true;
}
public static bool Measure(
Bitmap png,
out uint nTextX, out uint nTextY, out uint nTextWidth, out uint nTextHeight,
out uint nOutlineX, out uint nOutlineY, out uint nOutlineWidth, out uint nOutlineHeight)
{
nTextX = nTextY = nTextWidth = nTextHeight = 0;
nOutlineX = nOutlineY = nOutlineWidth = nOutlineHeight = 0;
BitmapData bitmapData = new BitmapData();
Rectangle rect = new Rectangle(0, 0, png.Width, png.Height );
png.LockBits(
rect,
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb,
bitmapData );
unsafe
{
uint* pixels = (uint*)bitmapData.Scan0;
if( pixels==null )
return false;
uint col = 0;
int stride = bitmapData.Stride >> 2;
nTextX = 50000;
nTextY = 50000;
nTextWidth = 0;
nTextHeight = 0;
nOutlineX = 50000;
nOutlineY = 50000;
nOutlineWidth = 0;
nOutlineHeight = 0;
for(uint row = 0; row < bitmapData.Height; ++row)
{
for(col = 0; col < bitmapData.Width; ++col)
{
uint index = (uint)(row * stride + col);
byte red = (byte)((pixels[index] & 0xff0000) >> 16);
byte blue = (byte)(pixels[index] & 0xff);
if(red>0)
{
if(col<nOutlineX)
nOutlineX = col;
if(row<nOutlineY)
nOutlineY = row;
if(col>nOutlineWidth)
nOutlineWidth = col;
if(row>nOutlineHeight)
nOutlineHeight = row;
}
if(blue>0)
{
if(col<nTextX)
nTextX = col;
if(row<nTextY)
nTextY = row;
if(col>nTextWidth)
nTextWidth = col;
if(row>nTextHeight)
nTextHeight = row;
}
}
}
}
png.UnlockBits(bitmapData);
nTextWidth -= nTextX;
nTextHeight -= nTextY;
nOutlineWidth -= nOutlineX;
nOutlineHeight -= nOutlineY;
++nTextWidth;
++nTextHeight;
++nOutlineWidth;
++nOutlineHeight;
return true;
}
public Bitmap GetInternalMaskImage()
{
return m_pbmpMask;
}
public Bitmap GetResultImage()
{
return m_pbmpResult;
}
public Bitmap GetShadowImage()
{
return m_pbmpShadow;
}
private byte Clamp(uint val)
{
if(val>255)
return 255;
else
return (byte)(val);
}
private Bitmap m_pbmpResult;
private Bitmap m_pbmpMask;
private Bitmap m_pbmpShadow;
private Color m_clrBkgd;
private Color m_clrOutline;
private Color m_clrText;
private TextDesignerCSLibrary.PngOutlineText m_PngOutlineText;
private TextDesignerCSLibrary.PngOutlineText m_PngShadow;
}
}

View File

@@ -0,0 +1,812 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
namespace TextDesignerCSLibrary
{
/// <summary>
/// Class to store the font info to pass as parameter to the drawing methods.
/// </summary>
public class TextContext
{
public TextContext()
{
fontFamily = new System.Drawing.FontFamily("Arial");
fontStyle = System.Drawing.FontStyle.Regular;
nfontSize = 20;
pszText = null;
ptDraw = new System.Drawing.Point(0, 0);
strFormat = new System.Drawing.StringFormat();
}
/// <summary>
/// fontFamily is the font family
/// </summary>
public System.Drawing.FontFamily fontFamily;
/// <summary>
/// fontStyle is the font style, eg, bold, italic or bold
/// </summary>
public System.Drawing.FontStyle fontStyle;
/// <summary>
/// nfontSize is font size
/// </summary>
public int nfontSize;
/// <summary>
/// pszText is the text to be displayed
/// </summary>
public string pszText;
/// <summary>
/// ptDraw is the point to draw
/// </summary>
public System.Drawing.Point ptDraw;
/// <summary>
/// strFormat is the string format
/// </summary>
public System.Drawing.StringFormat strFormat;
}
/// <summary>
/// Class to draw text outlines
/// </summary>
public class Canvas
{
/// <summary>
/// Generate Text Glow strategy
/// </summary>
/// <param name="clrText">is the color of the text</param>
/// <param name="clrOutline">is the color of the glow outline</param>
/// <param name="nThickness">is the thickness of the outline in pixels</param>
/// <returns>valid ITextStrategy pointer if successful</returns>
public static ITextStrategy TextGlow(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline,
int nThickness)
{
TextGlowStrategy strat = new TextGlowStrategy();
strat.Init(clrText, clrOutline, nThickness);
return strat;
}
/// <summary>
/// Generate Text Glow strategy
/// </summary>
/// <param name="brushText">is the brush of the text</param>
/// <param name="clrOutline">is the color of the glow outline</param>
/// <param name="nThickness">is the thickness of the outline in pixels</param>
/// <returns>valid ITextStrategy pointer if successful</returns>
public static ITextStrategy TextGlow(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline,
int nThickness)
{
TextGlowStrategy strat = new TextGlowStrategy();
strat.Init(brushText, clrOutline, nThickness);
return strat;
}
/// <summary>
/// Generate Text Outline strategy
/// </summary>
/// <param name="clrText">is the color of the text</param>
/// <param name="clrOutline">is the color of the outline</param>
/// <param name="nThickness">is the thickness of the outline in pixels</param>
/// <returns>valid ITextStrategy pointer if successful</returns>
public static ITextStrategy TextOutline(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline,
int nThickness)
{
TextOutlineStrategy strat = new TextOutlineStrategy();
strat.Init(clrText, clrOutline, nThickness);
return strat;
}
/// <summary>
/// Generate Text Outline strategy
/// </summary>
/// <param name="brushText">is the brush of the text</param>
/// <param name="clrOutline">is the color of the outline</param>
/// <param name="nThickness">is the thickness of the outline in pixels</param>
/// <returns>valid ITextStrategy pointer if successful</returns>
public static ITextStrategy TextOutline(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline,
int nThickness)
{
TextOutlineStrategy strat = new TextOutlineStrategy();
strat.Init(brushText, clrOutline, nThickness);
return strat;
}
/// <summary>
/// Setting Gradient Outlined Text effect
/// </summary>
/// <param name="clrText">is the text color</param>
/// <param name="clrOutline1">is the inner outline color</param>
/// <param name="clrOutline2">is the outer outline color</param>
/// <param name="nThickness">is the outline thickness</param>
/// <returns>valid ITextStrategy pointer if successful</returns>
public static ITextStrategy TextGradOutline(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness)
{
TextGradOutlineStrategy strat = new TextGradOutlineStrategy();
strat.Init(clrText, clrOutline1, clrOutline2, nThickness);
return strat;
}
/// <summary>
/// Setting Gradient Outlined Text effect
/// </summary>
/// <param name="brushText">is the text brush</param>
/// <param name="clrOutline1">is the inner outline color</param>
/// <param name="clrOutline2">is the outer outline color</param>
/// <param name="nThickness">is the outline thickness</param>
/// <returns>valid ITextStrategy pointer if successful</returns>
public static ITextStrategy TextGradOutline(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness)
{
TextGradOutlineStrategy strat = new TextGradOutlineStrategy();
strat.Init(brushText, clrOutline1, clrOutline2, nThickness);
return strat;
}
/// <summary>
/// Setting just Text effect with no outline
/// </summary>
/// <param name="clrText">is the text color</param>
/// <returns>valid ITextStrategy pointer if successful</returns>
public static ITextStrategy TextNoOutline(
System.Drawing.Color clrText)
{
TextNoOutlineStrategy strat = new TextNoOutlineStrategy();
strat.Init(clrText);
return strat;
}
/// <summary>
/// Setting just Text effect with no outline
/// </summary>
/// <param name="brushText">is the text brush</param>
/// <returns>valid ITextStrategy pointer if successful</returns>
public static ITextStrategy TextNoOutline(
System.Drawing.Brush brushText)
{
TextNoOutlineStrategy strat = new TextNoOutlineStrategy();
strat.Init(brushText);
return strat;
}
/// <summary>
/// Setting Outlined Text effect with no text fill
/// </summary>
/// <param name="clrOutline">is the outline color</param>
/// <param name="nThickness">is the outline thickness</param>
/// <param name="bRoundedEdge">specifies rounded or sharp edges</param>
/// <returns>valid ITextStrategy pointer if successful</returns>
public static ITextStrategy TextOnlyOutline(
System.Drawing.Color clrOutline,
int nThickness,
bool bRoundedEdge)
{
TextOnlyOutlineStrategy strat = new TextOnlyOutlineStrategy();
strat.Init(clrOutline, nThickness, bRoundedEdge);
return strat;
}
/// <summary>
/// Generate a canvas image based on width and height
/// </summary>
/// <param name="width">is the image width</param>
/// <param name="height">is the image height</param>
/// <returns>a valid canvas image if successful</returns>
public static System.Drawing.Bitmap GenImage(int width, int height)
{
return new System.Drawing.Bitmap(width, height, PixelFormat.Format32bppArgb);
}
/// <summary>
/// Generate a canvas image based on width and height
/// </summary>
/// <param name="width">is the image width</param>
/// <param name="height">is the image height</param>
/// <param name="colors">is the list of colors for the gradient</param>
/// <param name="horizontal">specifies whether the gradient is horizontal</param>
/// <returns>a valid canvas image if successful</returns>
public static System.Drawing.Bitmap GenImage(int width, int height, List<System.Drawing.Color> colors, bool horizontal)
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height, PixelFormat.Format32bppArgb);
DrawGradient.Draw(bmp, colors, horizontal);
return bmp;
}
/// <summary>
/// Generate a canvas image based on width and height
/// </summary>
/// <param name="width">is the image width</param>
/// <param name="height">is the image height</param>
/// <param name="clr">is the color to paint the image</param>
/// <returns>a valid canvas image if successful</returns>
public static System.Drawing.Bitmap GenImage(int width, int height, System.Drawing.Color clr)
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height, PixelFormat.Format32bppArgb);
BitmapData bitmapData = new BitmapData();
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
bmp.LockBits(
rect,
ImageLockMode.WriteOnly,
PixelFormat.Format32bppArgb,
bitmapData);
unsafe
{
uint* pixels = (uint*)bitmapData.Scan0;
if (pixels == null)
return null;
uint col = 0;
int stride = bitmapData.Stride >> 2;
uint color = (uint)(clr.A << 24 | clr.R << 16 | clr.G << 8 | clr.G);
for (uint row = 0; row < bitmapData.Height; ++row)
{
for (col = 0; col < bitmapData.Width; ++col)
{
uint index = (uint)(row * stride + col);
pixels[index] = color;
}
}
}
bmp.UnlockBits(bitmapData);
return bmp;
}
/// <summary>
/// Generate a canvas image based on width and height
/// </summary>
/// <param name="width">is the image width</param>
/// <param name="height">is the image height</param>
/// <param name="clr">is the color to paint the image</param>
/// <param name="alpha">is alpha of the color</param>
/// <returns>a valid canvas image if successful</returns>
public static System.Drawing.Bitmap GenImage(int width, int height, System.Drawing.Color clr, byte alpha)
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height, PixelFormat.Format32bppArgb);
BitmapData bitmapData = new BitmapData();
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
bmp.LockBits(
rect,
ImageLockMode.WriteOnly,
PixelFormat.Format32bppArgb,
bitmapData);
unsafe
{
uint* pixels = (uint*)bitmapData.Scan0;
if (pixels == null)
return null;
uint col = 0;
int stride = bitmapData.Stride >> 2;
uint color = (uint)(alpha << 24 | clr.R << 16 | clr.G << 8 | clr.G);
for (uint row = 0; row < bitmapData.Height; ++row)
{
for (col = 0; col < bitmapData.Width; ++col)
{
uint index = (uint)(row * stride + col);
pixels[index] = color;
}
}
}
bmp.UnlockBits(bitmapData);
return bmp;
}
/// <summary>
/// Generate mask image of the text strategy.
/// </summary>
/// <param name="strategy">is text strategy</param>
/// <param name="width">is the mask image width</param>
/// <param name="height">is the mask image height</param>
/// <param name="offset">offsets the text (typically used for shadows)</param>
/// <param name="textContext">is text context</param>
/// <returns>a valid mask image if successful</returns>
public static System.Drawing.Bitmap GenMask(
ITextStrategy strategy,
int width,
int height,
System.Drawing.Point offset,
TextContext textContext)
{
if (strategy == null || textContext == null)
return null;
System.Drawing.Bitmap pBmp = new System.Drawing.Bitmap(width, height, PixelFormat.Format32bppArgb);
using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(pBmp))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
strategy.DrawString(graphics,
textContext.fontFamily,
textContext.fontStyle,
textContext.nfontSize,
textContext.pszText,
new System.Drawing.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y),
textContext.strFormat);
}
return pBmp;
}
/// <summary>
/// Measure the mask image based on the mask color.
/// </summary>
/// <param name="mask">is the mask image to be measured</param>
/// <param name="maskColor">is mask color used in mask image</param>
/// <param name="top">returns the topmost Y </param>
/// <param name="left">returns the leftmost X</param>
/// <param name="bottom">returns the bottommost Y</param>
/// <param name="right">returns the rightmost X</param>
/// <returns>true if successful</returns>
public static bool MeasureMaskLength(
System.Drawing.Bitmap mask,
System.Drawing.Color maskColor,
ref uint top,
ref uint left,
ref uint bottom,
ref uint right)
{
top = 30000;
left = 30000;
bottom = 0;
right = 0;
if (mask == null)
return false;
BitmapData bitmapDataMask = new BitmapData();
Rectangle rect = new Rectangle(0, 0, mask.Width, mask.Height);
mask.LockBits(
rect,
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb,
bitmapDataMask);
unsafe
{
uint* pixelsMask = (uint*)bitmapDataMask.Scan0;
if (pixelsMask == null)
return false;
uint col = 0;
int stride = bitmapDataMask.Stride >> 2;
for (uint row = 0; row < bitmapDataMask.Height; ++row)
{
for (col = 0; col < bitmapDataMask.Width; ++col)
{
uint index = (uint)(row * stride + col);
byte nAlpha = 0;
if (MaskColor.IsEqual(maskColor, MaskColor.Red))
nAlpha = (Byte)((pixelsMask[index] & 0xff0000) >> 16);
else if (MaskColor.IsEqual(maskColor, MaskColor.Green))
nAlpha = (Byte)((pixelsMask[index] & 0xff00) >> 8);
else if (MaskColor.IsEqual(maskColor, MaskColor.Blue))
nAlpha = (Byte)(pixelsMask[index] & 0xff);
if (nAlpha > 0)
{
if (col < left)
left = col;
if (row < top)
top = row;
if (col > right)
right = col;
if (row > bottom)
bottom = row;
}
}
}
}
mask.UnlockBits(bitmapDataMask);
return true;
}
/// <summary>
/// Apply image to mask onto the canvas
/// </summary>
/// <param name="image">is the image to be used</param>
/// <param name="mask">is the mask image to be read</param>
/// <param name="canvas">is the destination image to be draw upon</param>
/// <param name="maskColor">is mask color used in mask image</param>
/// <returns>true if successful</returns>
public static bool ApplyImageToMask(
System.Drawing.Bitmap image,
System.Drawing.Bitmap mask,
System.Drawing.Bitmap canvas,
System.Drawing.Color maskColor)
{
if (image == null || mask == null || canvas == null)
return false;
BitmapData bitmapDataImage = new BitmapData();
BitmapData bitmapDataMask = new BitmapData();
BitmapData bitmapDataCanvas = new BitmapData();
Rectangle rectCanvas = new Rectangle(0, 0, canvas.Width, canvas.Height);
Rectangle rectMask = new Rectangle(0, 0, mask.Width, mask.Height);
Rectangle rectImage = new Rectangle(0, 0, image.Width, image.Height);
image.LockBits(
rectImage,
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb,
bitmapDataImage);
mask.LockBits(
rectMask,
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb,
bitmapDataMask);
canvas.LockBits(
rectCanvas,
ImageLockMode.WriteOnly,
PixelFormat.Format32bppArgb,
bitmapDataCanvas);
unsafe
{
uint* pixelsImage = (uint*)bitmapDataImage.Scan0;
uint* pixelsMask = (uint*)bitmapDataMask.Scan0;
uint* pixelsCanvas = (uint*)bitmapDataCanvas.Scan0;
if (pixelsImage == null || pixelsMask == null || pixelsCanvas == null)
return false;
uint col = 0;
int stride = bitmapDataCanvas.Stride >> 2;
for (uint row = 0; row < bitmapDataCanvas.Height; ++row)
{
for (col = 0; col < bitmapDataCanvas.Width; ++col)
{
if (row >= bitmapDataImage.Height || col >= bitmapDataImage.Width)
continue;
if (row >= bitmapDataMask.Height || col >= bitmapDataMask.Width)
continue;
uint index = (uint)(row * stride + col);
uint indexMask = (uint)(row * (bitmapDataMask.Stride >> 2) + col);
uint indexImage = (uint)(row * (bitmapDataImage.Stride >> 2) + col);
byte maskByte = 0;
if (MaskColor.IsEqual(maskColor, MaskColor.Red))
maskByte = (Byte)((pixelsMask[indexMask] & 0xff0000) >> 16);
else if (MaskColor.IsEqual(maskColor, MaskColor.Green))
maskByte = (Byte)((pixelsMask[indexMask] & 0xff00) >> 8);
else if (MaskColor.IsEqual(maskColor, MaskColor.Blue))
maskByte = (Byte)(pixelsMask[indexMask] & 0xff);
if (maskByte > 0)
pixelsCanvas[index] = Alphablend(pixelsCanvas[index], pixelsImage[indexImage], (Byte)(pixelsMask[indexMask] >> 24), (Byte)(pixelsMask[indexMask] >> 24));
}
}
}
canvas.UnlockBits(bitmapDataCanvas);
mask.UnlockBits(bitmapDataMask);
image.UnlockBits(bitmapDataImage);
return true;
}
/// <summary>
/// Apply color to mask onto the canvas
/// </summary>
/// <param name="clr">is the color to be used</param>
/// <param name="mask">is the mask image to be read</param>
/// <param name="canvas">is the destination image to be draw upon</param>
/// <param name="maskColor">is mask color used in mask image</param>
/// <returns>true if successful</returns>
public static bool ApplyColorToMask(
System.Drawing.Color clr,
System.Drawing.Bitmap mask,
System.Drawing.Bitmap canvas,
System.Drawing.Color maskColor)
{
if (mask == null || canvas == null)
return false;
BitmapData bitmapDataMask = new BitmapData();
BitmapData bitmapDataCanvas = new BitmapData();
Rectangle rectCanvas = new Rectangle(0, 0, canvas.Width, canvas.Height);
Rectangle rectMask = new Rectangle(0, 0, mask.Width, mask.Height);
mask.LockBits(
rectMask,
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb,
bitmapDataMask);
canvas.LockBits(
rectCanvas,
ImageLockMode.WriteOnly,
PixelFormat.Format32bppArgb,
bitmapDataCanvas);
unsafe
{
uint* pixelsMask = (uint*)bitmapDataMask.Scan0;
uint* pixelsCanvas = (uint*)bitmapDataCanvas.Scan0;
if (pixelsMask == null || pixelsCanvas == null)
return false;
uint col = 0;
int stride = bitmapDataCanvas.Stride >> 2;
for (uint row = 0; row < bitmapDataCanvas.Height; ++row)
{
for (col = 0; col < bitmapDataCanvas.Width; ++col)
{
if (row >= bitmapDataMask.Height || col >= bitmapDataMask.Width)
continue;
uint index = (uint)(row * stride + col);
uint indexMask = (uint)(row * (bitmapDataMask.Stride >> 2) + col);
byte maskByte = 0;
if (MaskColor.IsEqual(maskColor, MaskColor.Red))
maskByte = (Byte)((pixelsMask[indexMask] & 0xff0000) >> 16);
else if (MaskColor.IsEqual(maskColor, MaskColor.Green))
maskByte = (Byte)((pixelsMask[indexMask] & 0xff00) >> 8);
else if (MaskColor.IsEqual(maskColor, MaskColor.Blue))
maskByte = (Byte)(pixelsMask[indexMask] & 0xff);
uint color = (uint)(0xff << 24 | clr.R << 16 | clr.G << 8 | clr.B);
if (maskByte > 0)
pixelsCanvas[index] = Alphablend(pixelsCanvas[index], color, (Byte)(pixelsMask[indexMask] >> 24), (Byte)(pixelsMask[indexMask] >> 24));
}
}
}
canvas.UnlockBits(bitmapDataCanvas);
mask.UnlockBits(bitmapDataMask);
return true;
}
/// <summary>
/// Apply color to mask onto the canvas
/// </summary>
/// <param name="clr">is the color to be used</param>
/// <param name="mask">is the mask image to be read</param>
/// <param name="canvas">is the destination image to be draw upon</param>
/// <param name="maskColor">is mask color used in mask image</param>
/// <param name="offset">determine how much to offset the mask</param>
/// <returns>true if successful</returns>
public static bool ApplyColorToMask(
System.Drawing.Color clr,
System.Drawing.Bitmap mask,
System.Drawing.Bitmap canvas,
System.Drawing.Color maskColor,
System.Drawing.Point offset)
{
if (mask == null || canvas == null)
return false;
BitmapData bitmapDataMask = new BitmapData();
BitmapData bitmapDataCanvas = new BitmapData();
Rectangle rectCanvas = new Rectangle(0, 0, canvas.Width, canvas.Height);
Rectangle rectMask = new Rectangle(0, 0, mask.Width, mask.Height);
mask.LockBits(
rectMask,
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb,
bitmapDataMask);
canvas.LockBits(
rectCanvas,
ImageLockMode.WriteOnly,
PixelFormat.Format32bppArgb,
bitmapDataCanvas);
unsafe
{
uint* pixelsMask = (uint*)bitmapDataMask.Scan0;
uint* pixelsCanvas = (uint*)bitmapDataCanvas.Scan0;
if (pixelsMask == null || pixelsCanvas == null)
return false;
uint col = 0;
int stride = bitmapDataCanvas.Stride >> 2;
for (uint row = 0; row < bitmapDataCanvas.Height; ++row)
{
for (col = 0; col < bitmapDataCanvas.Width; ++col)
{
if ((row - offset.Y) >= bitmapDataMask.Height || (col - offset.X) >= bitmapDataMask.Width ||
(row - offset.Y) < 0 || (col - offset.X) < 0)
continue;
uint index = (uint)(row * stride + col);
uint indexMask = (uint)((row - offset.Y) * (bitmapDataMask.Stride >> 2) + (col - offset.X));
byte maskByte = 0;
if (MaskColor.IsEqual(maskColor, MaskColor.Red))
maskByte = (Byte)((pixelsMask[indexMask] & 0xff0000) >> 16);
else if (MaskColor.IsEqual(maskColor, MaskColor.Green))
maskByte = (Byte)((pixelsMask[indexMask] & 0xff00) >> 8);
else if (MaskColor.IsEqual(maskColor, MaskColor.Blue))
maskByte = (Byte)(pixelsMask[indexMask] & 0xff);
uint color = (uint)(0xff << 24 | clr.R << 16 | clr.G << 8 | clr.B);
if (maskByte > 0)
pixelsCanvas[index] = Alphablend(pixelsCanvas[index], color, (Byte)(pixelsMask[indexMask] >> 24), (Byte)(pixelsMask[indexMask] >> 24));
}
}
}
canvas.UnlockBits(bitmapDataCanvas);
mask.UnlockBits(bitmapDataMask);
return true;
}
/// <summary>
/// Draw outline on image
/// </summary>
/// <param name="strategy">is text strategy</param>
/// <param name="image">is the image to be draw upon</param>
/// <param name="offset">offsets the text (typically used for shadows)</param>
/// <param name="textContext">is text context</param>
/// <returns>true if successful</returns>
public static bool DrawTextImage(
ITextStrategy strategy,
System.Drawing.Bitmap image,
System.Drawing.Point offset,
TextContext textContext)
{
if (strategy == null || image == null || textContext == null)
return false;
bool bRet = false;
using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(image))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
bRet = strategy.DrawString(graphics,
textContext.fontFamily,
textContext.fontStyle,
textContext.nfontSize,
textContext.pszText,
new System.Drawing.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y),
textContext.strFormat);
}
return bRet;
}
/// <summary>
/// Set alpha to color
/// </summary>
/// <param name="dest">is destination color in ARGB</param>
/// <param name="source">is source color in ARGB</param>
/// <param name="nAlpha">is nAlpha is alpha channel</param>
/// <returns></returns>
private static UInt32 AddAlpha(UInt32 dest, UInt32 source, Byte nAlpha)
{
if (0 == nAlpha)
return dest;
if (255 == nAlpha)
return source;
Byte nSrcRed = (Byte)((source & 0xff0000) >> 16);
Byte nSrcGreen = (Byte)((source & 0xff00) >> 8);
Byte nSrcBlue = (Byte)((source & 0xff));
Byte nRed = (Byte)(nSrcRed);
Byte nGreen = (Byte)(nSrcGreen);
Byte nBlue = (Byte)(nSrcBlue);
return (UInt32)(nAlpha << 24 | nRed << 16 | nGreen << 8 | nBlue);
}
/// <summary>
/// Performs Alphablend
/// </summary>
/// <param name="dest">is destination color in ARGB</param>
/// <param name="source">is source color in ARGB</param>
/// <param name="nAlpha">is nAlpha is alpha channel</param>
/// <param name="nAlphaFinal">sets alpha channel of the returned UInt32</param>
/// <returns>destination color</returns>
private static UInt32 Alphablend(UInt32 dest, UInt32 source, Byte nAlpha, Byte nAlphaFinal)
{
if (0 == nAlpha)
return dest;
if (255 == nAlpha)
return source;
Byte nInvAlpha = (Byte)(~nAlpha);
Byte nSrcRed = (Byte)((source & 0xff0000) >> 16);
Byte nSrcGreen = (Byte)((source & 0xff00) >> 8);
Byte nSrcBlue = (Byte)((source & 0xff));
Byte nDestRed = (Byte)((dest & 0xff0000) >> 16);
Byte nDestGreen = (Byte)((dest & 0xff00) >> 8);
Byte nDestBlue = (Byte)(dest & 0xff);
Byte nRed = (Byte)((nSrcRed * nAlpha + nDestRed * nInvAlpha) >> 8);
Byte nGreen = (Byte)((nSrcGreen * nAlpha + nDestGreen * nInvAlpha) >> 8);
Byte nBlue = (Byte)((nSrcBlue * nAlpha + nDestBlue * nInvAlpha) >> 8);
return (UInt32)(nAlphaFinal << 24 | nRed << 16 | nGreen << 8 | nBlue);
}
/// <summary>
/// Performs Alphablend
/// </summary>
/// <param name="dest">is destination color in ARGB</param>
/// <param name="source">is source color in ARGB</param>
/// <returns>destination color</returns>
private static UInt32 PreMultipliedAlphablend(UInt32 dest, UInt32 source)
{
Byte Alpha = (Byte)((source & 0xff000000) >> 24);
Byte nInvAlpha = (Byte)(255 - Alpha);
Byte nSrcRed = (Byte)((source & 0xff0000) >> 16);
Byte nSrcGreen = (Byte)((source & 0xff00) >> 8);
Byte nSrcBlue = (Byte)((source & 0xff));
Byte nDestRed = (Byte)((dest & 0xff0000) >> 16);
Byte nDestGreen = (Byte)((dest & 0xff00) >> 8);
Byte nDestBlue = (Byte)(dest & 0xff);
Byte nRed = (Byte)(nSrcRed + ((nDestRed * nInvAlpha) >> 8));
Byte nGreen = (Byte)(nSrcGreen + ((nDestGreen * nInvAlpha) >> 8));
Byte nBlue = (Byte)(nSrcBlue + ((nDestBlue * nInvAlpha) >> 8));
return (UInt32)(0xff << 24 | nRed << 16 | nGreen << 8 | nBlue);
}
}
}

View File

@@ -0,0 +1,272 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace TextDesignerCSLibrary
{
class DiffusedShadowStrategy : ITextStrategy
{
public DiffusedShadowStrategy()
{
m_nThickness=8;
m_bOutlinetext = false;
m_brushText = null;
m_bClrText = true;
disposed = false;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
}
disposed = true;
}
}
~DiffusedShadowStrategy()
{
Dispose(false);
}
public ITextStrategy Clone()
{
DiffusedShadowStrategy p = new DiffusedShadowStrategy();
if (m_bClrText)
p.Init(m_clrText, m_clrOutline, m_nThickness, m_bOutlinetext);
else
p.Init(m_brushText, m_clrOutline, m_nThickness, m_bOutlinetext);
return (ITextStrategy)(p);
}
public void Init(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline,
int nThickness,
bool bOutlinetext)
{
m_clrText = clrText;
m_bClrText = true;
m_clrOutline = clrOutline;
m_nThickness = nThickness;
m_bOutlinetext = bOutlinetext;
}
public void Init(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline,
int nThickness,
bool bOutlinetext)
{
m_brushText = brushText;
m_bClrText = false;
m_clrOutline = clrOutline;
m_nThickness = nThickness;
m_bOutlinetext = bOutlinetext;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
for (int i = 1; i <= m_nThickness; ++i)
{
using (Pen pen = new Pen(m_clrOutline, i))
{
pen.LineJoin = LineJoin.Round;
graphics.DrawPath(pen, path);
}
}
if (m_bOutlinetext == false)
{
for (int i = 1; i <= m_nThickness; ++i)
{
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
}
else
{
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
}
return true;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
for (int i = 1; i <= m_nThickness; ++i)
{
using (Pen pen = new Pen(m_clrOutline, i))
{
pen.LineJoin = LineJoin.Round;
graphics.DrawPath(pen, path);
}
}
if (m_bOutlinetext == false)
{
for (int i = 1; i <= m_nThickness; ++i)
{
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
}
else
{
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
fDestWidth = ptDraw.X;
fDestHeight = ptDraw.Y;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
fDestWidth = rtDraw.Width;
fDestHeight = rtDraw.Height;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
protected System.Drawing.Color m_clrText;
protected System.Drawing.Color m_clrOutline;
protected int m_nThickness;
protected bool m_bOutlinetext;
protected System.Drawing.Brush m_brushText;
protected bool m_bClrText;
protected bool disposed;
}
}

View File

@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace TextDesignerCSLibrary
{
public class DrawGradient
{
public static bool Draw(Bitmap bmp, List<Color> colors, bool bHorizontal)
{
if(colors.Count==0)
return false;
if(colors.Count==1)
{
using (Graphics graph = Graphics.FromImage(bmp))
{
using (SolidBrush brush = new SolidBrush(colors[0]))
{
graph.FillRectangle(brush, 0, 0, bmp.Width, bmp.Height);
}
}
}
else if (bHorizontal)
{
using (Graphics graph = Graphics.FromImage(bmp))
{
int gradRectNum = colors.Count - 1;
int gradWidth = bmp.Width / gradRectNum;
int remainder = bmp.Width % gradRectNum;
int TotalWidthRendered = 0;
int WidthToBeRendered = 0;
for (int i = 0; i < gradRectNum; ++i)
{
int addRemainder = 0;
if (i < remainder)
addRemainder = 1;
WidthToBeRendered = gradWidth + addRemainder;
Rectangle rect = new Rectangle(TotalWidthRendered - 1, 0, WidthToBeRendered + 1, bmp.Height);
using (LinearGradientBrush brush = new LinearGradientBrush(rect, colors[i], colors[i + 1], LinearGradientMode.Horizontal))
{
graph.FillRectangle(brush, TotalWidthRendered, 0, WidthToBeRendered, bmp.Height);
}
TotalWidthRendered += WidthToBeRendered;
}
}
}
else
{
using (Graphics graph = Graphics.FromImage(bmp))
{
int gradRectNum = colors.Count - 1;
int gradHeight = bmp.Height / gradRectNum;
int remainder = bmp.Height % gradRectNum;
int TotalHeightRendered = 0;
int HeightToBeRendered = 0;
for (int i = 0; i < gradRectNum; ++i)
{
int addRemainder = 0;
if (i < remainder)
addRemainder = 1;
HeightToBeRendered = gradHeight + addRemainder;
Rectangle rect = new Rectangle(0, TotalHeightRendered - 1, bmp.Width, HeightToBeRendered + 1);
using (LinearGradientBrush brush = new LinearGradientBrush(rect, colors[i], colors[i + 1], LinearGradientMode.Vertical))
{
graph.FillRectangle(brush, 0, TotalHeightRendered, bmp.Width, HeightToBeRendered);
}
TotalHeightRendered += HeightToBeRendered;
}
}
}
return true;
}
}
}

View File

@@ -0,0 +1,273 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace TextDesignerCSLibrary
{
public class ExtrudeStrategy : ITextStrategy
{
public ExtrudeStrategy()
{
m_nThickness=2;
m_brushText = null;
m_bClrText = true;
disposed = false;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
}
disposed = true;
}
}
~ExtrudeStrategy()
{
Dispose(false);
}
public ITextStrategy Clone()
{
ExtrudeStrategy p = new ExtrudeStrategy();
if (m_bClrText)
p.Init(m_clrText, m_clrOutline, m_nThickness, m_nOffsetX, m_nOffsetY);
else
p.Init(m_brushText, m_clrOutline, m_nThickness, m_nOffsetX, m_nOffsetY);
return (ITextStrategy)(p);
}
public void Init(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline,
int nThickness,
int nOffsetX,
int nOffsetY )
{
m_clrText = clrText;
m_bClrText = true;
m_clrOutline = clrOutline;
m_nThickness = nThickness;
m_nOffsetX = nOffsetX;
m_nOffsetY = nOffsetY;
}
public void Init(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline,
int nThickness,
int nOffsetX,
int nOffsetY)
{
m_brushText = brushText;
m_bClrText = false;
m_clrOutline = clrOutline;
m_nThickness = nThickness;
m_nOffsetX = nOffsetX;
m_nOffsetY = nOffsetY;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat)
{
int nOffset = Math.Abs(m_nOffsetX);
if (Math.Abs(m_nOffsetX) == Math.Abs(m_nOffsetY))
{
nOffset = Math.Abs(m_nOffsetX);
}
else if (Math.Abs(m_nOffsetX) > Math.Abs(m_nOffsetY))
{
nOffset = Math.Abs(m_nOffsetY);
}
else if (Math.Abs(m_nOffsetX) < Math.Abs(m_nOffsetY))
{
nOffset = Math.Abs(m_nOffsetX);
}
for(int i=0; i<nOffset; ++i)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize,
new Point(ptDraw.X + ((i * (-m_nOffsetX)) / nOffset), ptDraw.Y + ((i * (-m_nOffsetY)) / nOffset)),
strFormat);
using (Pen pen = new Pen(m_clrOutline, m_nThickness))
{
pen.LineJoin = LineJoin.Round;
graphics.DrawPath(pen, path);
}
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
}
return true;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat)
{
int nOffset = Math.Abs(m_nOffsetX);
if (Math.Abs(m_nOffsetX) == Math.Abs(m_nOffsetY))
{
nOffset = Math.Abs(m_nOffsetX);
}
else if (Math.Abs(m_nOffsetX) > Math.Abs(m_nOffsetY))
{
nOffset = Math.Abs(m_nOffsetY);
}
else if (Math.Abs(m_nOffsetX) < Math.Abs(m_nOffsetY))
{
nOffset = Math.Abs(m_nOffsetX);
}
for (int i = 0; i < nOffset; ++i)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize,
new Rectangle(rtDraw.X + ((i * (-m_nOffsetX)) / nOffset), rtDraw.Y + ((i * (-m_nOffsetY)) / nOffset),
rtDraw.Width, rtDraw.Height),
strFormat);
using (Pen pen = new Pen(m_clrOutline, m_nThickness))
{
pen.LineJoin = LineJoin.Round;
graphics.DrawPath(pen, path);
}
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
fDestWidth = ptDraw.X;
fDestHeight = ptDraw.Y;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
fDestWidth = rtDraw.Width;
fDestHeight = rtDraw.Height;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
protected System.Drawing.Color m_clrText;
protected System.Drawing.Color m_clrOutline;
protected int m_nThickness;
protected int m_nOffsetX;
protected int m_nOffsetY;
protected System.Drawing.Brush m_brushText;
protected bool m_bClrText;
protected bool disposed;
}
}

View File

@@ -0,0 +1,181 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace TextDesignerCSLibrary
{
public class GDIPath
{
static public bool MeasureGraphicsPath(
System.Drawing.Graphics graphics,
System.Drawing.Drawing2D.GraphicsPath graphicsPath,
ref float fStartX,
ref float fStartY,
ref float fPixelsWidth,
ref float fPixelsHeight)
{
if(graphicsPath.PathData.Points.Length<=0)
return false;
float fHighestX = graphicsPath.PathData.Points[0].X;
float fHighestY = graphicsPath.PathData.Points[0].Y;
float fLowestX = graphicsPath.PathData.Points[0].X;
float fLowestY = graphicsPath.PathData.Points[0].Y;
int length = graphicsPath.PathData.Points.Length;
PointF[] points = graphicsPath.PathData.Points;
for(int i=1; i<length; ++i)
{
if (points[i].X < fLowestX)
fLowestX = points[i].X;
if (points[i].Y < fLowestY)
fLowestY = points[i].Y;
if (points[i].X > fHighestX)
fHighestX = points[i].X;
if (points[i].Y > fHighestY)
fHighestY = points[i].Y;
}
// Hack!
if (fLowestX < 0.0f)
{
fStartX = fLowestX;
fLowestX = -fLowestX;
}
else
{
fStartX = fLowestX;
fLowestX = 0.0f;
}
if (fLowestY < 0.0f)
{
fStartY = fLowestY;
fLowestY = -fLowestY;
}
else
{
fStartY = fLowestY;
fLowestY = 0.0f;
}
bool b = ConvertToPixels(
graphics,
fLowestX + fHighestX - fPixelsWidth,
fLowestY + fHighestY - fPixelsHeight,
ref fStartX,
ref fStartY,
ref fPixelsWidth,
ref fPixelsHeight );
return b;
}
static public bool MeasureGraphicsPathRealHeight(
System.Drawing.Graphics graphics,
System.Drawing.Drawing2D.GraphicsPath graphicsPath,
ref float fStartX,
ref float fStartY,
ref float fPixelsWidth,
ref float fPixelsHeight)
{
if (graphicsPath.PathData.Points.Length <= 0)
return false;
float fHighestX = graphicsPath.PathData.Points[0].X;
float fHighestY = graphicsPath.PathData.Points[0].Y;
float fLowestX = graphicsPath.PathData.Points[0].X;
float fLowestY = graphicsPath.PathData.Points[0].Y;
int length = graphicsPath.PathData.Points.Length;
PointF[] points = graphicsPath.PathData.Points;
for (int i = 1; i < length; ++i)
{
if (points[i].X < fLowestX)
fLowestX = points[i].X;
if (points[i].Y < fLowestY)
fLowestY = points[i].Y;
if (points[i].X > fHighestX)
fHighestX = points[i].X;
if (points[i].Y > fHighestY)
fHighestY = points[i].Y;
}
fStartX = fLowestX;
fStartY = fLowestY;
bool b = ConvertToPixels(
graphics,
fLowestX + fHighestX - fPixelsWidth,
fLowestY + fHighestY - fPixelsHeight,
ref fStartX,
ref fStartY,
ref fPixelsWidth,
ref fPixelsHeight);
return b;
}
static public bool ConvertToPixels(
System.Drawing.Graphics graphics,
float fSrcWidth,
float fSrcHeight,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
GraphicsUnit unit = graphics.PageUnit;
float fDpiX = graphics.DpiX;
float fDpiY = graphics.DpiY;
if(unit==GraphicsUnit.World)
return false; // dunno how to convert
if(unit==GraphicsUnit.Display||unit==GraphicsUnit.Pixel)
{
fDestWidth = fSrcWidth;
fDestHeight = fSrcHeight;
return true;
}
if(unit==GraphicsUnit.Point)
{
fStartX = 1.0f / 72.0f * fDpiX * fStartX;
fStartY = 1.0f / 72.0f * fDpiY * fStartY;
fDestWidth = 1.0f / 72.0f * fDpiX * fSrcWidth;
fDestHeight = 1.0f / 72.0f * fDpiY * fSrcHeight;
return true;
}
if(unit==GraphicsUnit.Inch)
{
fStartX = fDpiX * fStartX;
fStartY = fDpiY * fStartY;
fDestWidth = fDpiX * fSrcWidth;
fDestHeight = fDpiY * fSrcHeight;
return true;
}
if(unit==GraphicsUnit.Document)
{
fStartX = 1.0f / 300.0f * fDpiX * fStartX;
fStartY = 1.0f / 300.0f * fDpiY * fStartY;
fDestWidth = 1.0f / 300.0f * fDpiX * fSrcWidth;
fDestHeight = 1.0f / 300.0f * fDpiY * fSrcHeight;
return true;
}
if(unit==GraphicsUnit.Millimeter)
{
fStartX = 1.0f / 25.4f * fDpiX * fStartX;
fStartY = 1.0f / 25.4f * fDpiY * fStartY;
fDestWidth = 1.0f / 25.4f * fDpiX * fSrcWidth;
fDestHeight = 1.0f / 25.4f * fDpiY * fSrcHeight;
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace TextDesignerCSLibrary
{
public interface IOutlineText : IDisposable
{
void TextGlow(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline,
int nThickness);
void TextGlow(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline,
int nThickness);
void TextOutline(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline,
int nThickness);
void TextOutline(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline,
int nThickness);
void TextDblOutline(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness1,
int nThickness2);
void TextDblOutline(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness1,
int nThickness2);
void TextDblGlow(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness1,
int nThickness2);
void TextDblGlow(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness1,
int nThickness2);
void TextNoOutline(System.Drawing.Color clrText);
void TextNoOutline(System.Drawing.Brush brushText);
void TextOnlyOutline(
System.Drawing.Color clrOutline,
int nThickness,
bool bRoundedEdge);
void SetShadowBkgd(System.Drawing.Bitmap pBitmap);
void SetShadowBkgd(System.Drawing.Color clrBkgd, int nWidth, int nHeight);
void SetNullTextEffect();
void SetNullShadow();
void EnableShadow(bool bEnable);
void Shadow(
System.Drawing.Color color,
int nThickness,
System.Drawing.Point ptOffset);
bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int nfontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat);
bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int nfontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat pStrFormat);
bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int nfontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight );
bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int nfontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight );
}
}

View File

@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace TextDesignerCSLibrary
{
public interface ITextStrategy : IDisposable
{
ITextStrategy Clone();
bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat);
bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat);
bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string pszText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight);
bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string pszText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight);
}
}

View File

@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace TextDesignerCSLibrary
{
/// <summary>
/// Simple helper class to use mask color
/// </summary>
public class MaskColor
{
/// <summary>
/// Method to return a primary red color to be used as mask
/// </summary>
public static System.Drawing.Color Red
{
get
{
return System.Drawing.Color.FromArgb(0xFF, 0, 0);
}
}
/// <summary>
/// Method to return a primary green color to be used as mask
/// </summary>
public static System.Drawing.Color Green
{
get
{
return System.Drawing.Color.FromArgb(0, 0xFF, 0);
}
}
/// <summary>
/// Method to return a primary blue color to be used as mask
/// </summary>
public static System.Drawing.Color Blue
{
get
{
return System.Drawing.Color.FromArgb(0, 0, 0xFF);
}
}
/// <summary>
/// Method to compare 2 GDI+ color
/// </summary>
/// <param name="clr1">is 1st color</param>
/// <param name="clr2">is 2nd color</param>
/// <returns>true if equal</returns>
public static bool IsEqual(System.Drawing.Color clr1, System.Drawing.Color clr2)
{
if (clr1.R == clr2.R && clr1.G == clr2.G && clr1.B == clr2.B)
return true;
return false;
}
}
}

View File

@@ -0,0 +1,935 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace TextDesignerCSLibrary
{
public class OutlineText : IOutlineText
{
public OutlineText()
{
m_pTextStrategy = null;
m_pShadowStrategy = null;
m_pFontBodyShadow = null;
m_pBkgdBitmap = null;
m_clrShadow = System.Drawing.Color.FromArgb(0,0,0);
m_bEnableShadow = false;
m_bDiffuseShadow = false;
m_nShadowThickness = 2;
disposed = false;
}
public OutlineText(OutlineText rhs)
{
if (rhs.m_pTextStrategy != null) m_pTextStrategy = rhs.m_pTextStrategy.Clone(); else m_pTextStrategy = null;
if (rhs.m_pShadowStrategy != null) m_pShadowStrategy = rhs.m_pShadowStrategy.Clone(); else m_pShadowStrategy = null;
if (rhs.m_pFontBodyShadow != null) m_pFontBodyShadow = rhs.m_pFontBodyShadow.Clone(); else m_pFontBodyShadow = null;
m_pBkgdBitmap = rhs.m_pBkgdBitmap;
m_clrShadow = rhs.m_clrShadow;
m_bEnableShadow = rhs.m_bEnableShadow;
m_bDiffuseShadow = rhs.m_bDiffuseShadow;
m_nShadowThickness = rhs.m_nShadowThickness;
disposed = false;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
if (m_pTextStrategy != null)
m_pTextStrategy.Dispose();
if (m_pShadowStrategy != null)
m_pShadowStrategy.Dispose();
if (m_pFontBodyShadow != null)
m_pFontBodyShadow.Dispose();
if (m_pBkgdBitmap != null)
m_pBkgdBitmap.Dispose();
}
disposed = true;
}
}
~OutlineText()
{
Dispose(false);
}
public void TextGlow(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline,
int nThickness)
{
TextGlowStrategy pStrat = new TextGlowStrategy();
pStrat.Init(clrText,clrOutline,nThickness);
m_pTextStrategy = pStrat;
}
public void TextGlow(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline,
int nThickness)
{
TextGlowStrategy pStrat = new TextGlowStrategy();
pStrat.Init(brushText, clrOutline, nThickness);
m_pTextStrategy = pStrat;
}
public void TextOutline(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline,
int nThickness)
{
TextOutlineStrategy pStrat = new TextOutlineStrategy();
pStrat.Init(clrText,clrOutline,nThickness);
m_pTextStrategy = pStrat;
}
public void TextOutline(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline,
int nThickness)
{
TextOutlineStrategy pStrat = new TextOutlineStrategy();
pStrat.Init(brushText, clrOutline, nThickness);
m_pTextStrategy = pStrat;
}
public void TextDblOutline(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness1,
int nThickness2)
{
TextDblOutlineStrategy pStrat = new TextDblOutlineStrategy();
pStrat.Init(clrText,clrOutline1,clrOutline2,nThickness1,nThickness2);
m_pTextStrategy = pStrat;
}
public void TextDblOutline(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness1,
int nThickness2)
{
TextDblOutlineStrategy pStrat = new TextDblOutlineStrategy();
pStrat.Init(brushText, clrOutline1, clrOutline2, nThickness1, nThickness2);
m_pTextStrategy = pStrat;
}
public void TextDblGlow(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness1,
int nThickness2)
{
TextDblGlowStrategy pStrat = new TextDblGlowStrategy();
pStrat.Init(clrText, clrOutline1, clrOutline2, nThickness1, nThickness2);
m_pTextStrategy = pStrat;
}
public void TextDblGlow(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness1,
int nThickness2)
{
TextDblGlowStrategy pStrat = new TextDblGlowStrategy();
pStrat.Init(brushText, clrOutline1, clrOutline2, nThickness1, nThickness2);
m_pTextStrategy = pStrat;
}
public void TextGradOutline(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness)
{
TextGradOutlineStrategy pStrat = new TextGradOutlineStrategy();
pStrat.Init(clrText, clrOutline1, clrOutline2, nThickness);
m_pTextStrategy = pStrat;
}
public void TextGradOutline(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness)
{
TextGradOutlineStrategy pStrat = new TextGradOutlineStrategy();
pStrat.Init(brushText, clrOutline1, clrOutline2, nThickness);
m_pTextStrategy = pStrat;
}
public void TextNoOutline(System.Drawing.Color clrText)
{
TextNoOutlineStrategy pStrat = new TextNoOutlineStrategy();
pStrat.Init(clrText);
m_pTextStrategy = pStrat;
}
public void TextNoOutline(System.Drawing.Brush brushText)
{
TextNoOutlineStrategy pStrat = new TextNoOutlineStrategy();
pStrat.Init(brushText);
m_pTextStrategy = pStrat;
}
public void TextOnlyOutline(
System.Drawing.Color clrOutline,
int nThickness,
bool bRoundedEdge)
{
TextOnlyOutlineStrategy pStrat = new TextOnlyOutlineStrategy();
pStrat.Init(clrOutline, nThickness, bRoundedEdge);
m_pTextStrategy = pStrat;
}
public void SetShadowBkgd(System.Drawing.Bitmap pBitmap)
{
m_pBkgdBitmap = pBitmap;
}
public void SetShadowBkgd(System.Drawing.Color clrBkgd, int nWidth, int nHeight)
{
m_pBkgdBitmap = new System.Drawing.Bitmap(nWidth, nHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(m_pBkgdBitmap))
{
using (System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(clrBkgd))
{
graphics.FillRectangle(brush, 0, 0, m_pBkgdBitmap.Width, m_pBkgdBitmap.Height);
}
}
}
public void SetNullTextEffect()
{
m_pTextStrategy = null;
}
public void SetNullShadow()
{
m_pFontBodyShadow = null;
m_pShadowStrategy = null;
}
public void EnableShadow(bool bEnable)
{
m_bEnableShadow = bEnable;
}
public bool IsShadowEnabled()
{
return m_bEnableShadow;
}
public void Shadow(
System.Drawing.Color color,
int nThickness,
System.Drawing.Point ptOffset)
{
TextOutlineStrategy pStrat = new TextOutlineStrategy();
pStrat.Init(System.Drawing.Color.FromArgb(0,0,0,0),color,nThickness);
m_clrShadow = color;
TextOutlineStrategy pFontBodyShadow = new TextOutlineStrategy();
pFontBodyShadow.Init(System.Drawing.Color.FromArgb(255, 255, 255), System.Drawing.Color.FromArgb(0, 0, 0, 0), 0);
m_pFontBodyShadow = pFontBodyShadow;
m_ptShadowOffset = ptOffset;
m_pShadowStrategy = pStrat;
m_bDiffuseShadow = false;
}
public void DiffusedShadow(
System.Drawing.Color color,
int nThickness,
System.Drawing.Point ptOffset)
{
DiffusedShadowStrategy pStrat = new DiffusedShadowStrategy();
pStrat.Init(System.Drawing.Color.FromArgb(0,0,0,0),color,nThickness,true);
m_clrShadow = color;
DiffusedShadowStrategy pFontBodyShadow = new DiffusedShadowStrategy();
pFontBodyShadow.Init(System.Drawing.Color.FromArgb(color.A, 255, 255), System.Drawing.Color.FromArgb(0, 0, 0, 0), 0, true);
m_pFontBodyShadow = pFontBodyShadow;
m_ptShadowOffset = ptOffset;
m_pShadowStrategy = pStrat;
m_bDiffuseShadow = true;
m_bExtrudeShadow = false;
m_nShadowThickness = nThickness;
}
public void Extrude(
System.Drawing.Color color,
int nThickness,
System.Drawing.Point ptOffset)
{
ExtrudeStrategy pStrat = new ExtrudeStrategy();
pStrat.Init(System.Drawing.Color.FromArgb(0, 0, 0, 0), color, nThickness, ptOffset.X, ptOffset.Y);
m_clrShadow = color;
ExtrudeStrategy pFontBodyShadow = new ExtrudeStrategy();
pFontBodyShadow.Init(System.Drawing.Color.FromArgb(color.A, 255, 255), System.Drawing.Color.FromArgb(0, 0, 0, 0), 0, ptOffset.X, ptOffset.Y);
m_pFontBodyShadow = pFontBodyShadow;
m_ptShadowOffset = ptOffset;
m_pShadowStrategy = pStrat;
m_bExtrudeShadow = true;
m_bDiffuseShadow = false;
m_nShadowThickness = nThickness;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int nfontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat)
{
if (m_bEnableShadow && m_pShadowStrategy != null)
{
m_pShadowStrategy.DrawString(
graphics,
fontFamily,
fontStyle,
nfontSize,
strText,
new System.Drawing.Point(ptDraw.X+m_ptShadowOffset.X, ptDraw.Y+m_ptShadowOffset.Y),
strFormat);
}
if (m_bEnableShadow && m_pBkgdBitmap != null && m_pFontBodyShadow != null)
{
RenderFontShadow(
graphics,
fontFamily,
fontStyle,
nfontSize,
strText,
new System.Drawing.Point(ptDraw.X + m_ptShadowOffset.X, ptDraw.Y + m_ptShadowOffset.Y),
strFormat);
}
if (m_pTextStrategy != null)
{
return m_pTextStrategy.DrawString(
graphics,
fontFamily,
fontStyle,
nfontSize,
strText,
ptDraw,
strFormat);
}
return false;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int nfontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat)
{
if(m_bEnableShadow &&m_pShadowStrategy!=null)
{
m_pShadowStrategy.DrawString(
graphics,
fontFamily,
fontStyle,
nfontSize,
strText,
new System.Drawing.Rectangle(rtDraw.X+m_ptShadowOffset.X, rtDraw.Y+m_ptShadowOffset.Y,rtDraw.Width,rtDraw.Height),
strFormat);
}
if (m_bEnableShadow && m_pBkgdBitmap != null && m_pFontBodyShadow != null)
{
RenderFontShadow(
graphics,
fontFamily,
fontStyle,
nfontSize,
strText,
new System.Drawing.Rectangle(rtDraw.X + m_ptShadowOffset.X, rtDraw.Y + m_ptShadowOffset.Y, rtDraw.Width, rtDraw.Height),
strFormat);
}
if (m_pTextStrategy != null)
{
return m_pTextStrategy.DrawString(
graphics,
fontFamily,
fontStyle,
nfontSize,
strText,
rtDraw,
strFormat);
}
return false;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int nfontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
float fDestWidth1 = 0.0f;
float fDestHeight1 = 0.0f;
bool b = false;
if(m_pTextStrategy!=null)
{
b = m_pTextStrategy.MeasureString(
graphics,
fontFamily,
fontStyle,
nfontSize,
strText,
ptDraw,
strFormat,
ref fStartX,
ref fStartY,
ref fDestWidth1,
ref fDestHeight1 );
if(!b)
return false;
}
float fDestWidth2 = 0.0f;
float fDestHeight2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
if(m_bEnableShadow)
{
b = m_pShadowStrategy.MeasureString(
graphics,
fontFamily,
fontStyle,
nfontSize,
strText,
ptDraw,
strFormat,
ref fStartX2,
ref fStartY2,
ref fDestWidth2,
ref fDestHeight2 );
if(b)
{
float fDestWidth3 = 0.0f;
float fDestHeight3 = 0.0f;
float fStartX3 = 0.0f;
float fStartY3 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_ptShadowOffset.X, m_ptShadowOffset.Y,
ref fStartX3, ref fStartY3, ref fDestWidth3, ref fDestHeight3);
if(b)
{
fDestWidth2 += fDestWidth3;
fDestHeight2 += fDestHeight3;
}
}
else
return false;
}
if(fDestWidth1>fDestWidth2 || fDestHeight1>fDestHeight2)
{
fDestWidth = fDestWidth1;
fDestHeight = fDestHeight1;
}
else
{
fDestWidth = fDestWidth2;
fDestHeight = fDestHeight2;
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int nfontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
float fDestWidth1 = 0.0f;
float fDestHeight1 = 0.0f;
bool b = false;
if (m_pTextStrategy != null)
{
b = m_pTextStrategy.MeasureString(
graphics,
fontFamily,
fontStyle,
nfontSize,
strText,
rtDraw,
strFormat,
ref fStartX,
ref fStartY,
ref fDestWidth1,
ref fDestHeight1);
if (!b)
return false;
}
float fDestWidth2 = 0.0f;
float fDestHeight2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
if(m_bEnableShadow)
{
b = m_pShadowStrategy.MeasureString(
graphics,
fontFamily,
fontStyle,
nfontSize,
strText,
rtDraw,
strFormat,
ref fStartX2,
ref fStartY2,
ref fDestWidth2,
ref fDestHeight2 );
if(b)
{
float fDestWidth3 = 0.0f;
float fDestHeight3 = 0.0f;
float fStartX3 = 0.0f;
float fStartY3 = 0.0f;
b = GDIPath.ConvertToPixels(graphics,m_ptShadowOffset.X,m_ptShadowOffset.Y,
ref fStartX3, ref fStartY3, ref fDestWidth3, ref fDestHeight3);
if(b)
{
fDestWidth2 += fDestWidth3;
fDestHeight2 += fDestHeight3;
}
}
else
return false;
}
if(fDestWidth1>fDestWidth2 || fDestHeight1>fDestHeight2)
{
fDestWidth = fDestWidth1;
fDestHeight = fDestHeight1;
}
else
{
fDestWidth = fDestWidth2;
fDestHeight = fDestHeight2;
}
return true;
}
void RenderFontShadow(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int nfontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat)
{
Rectangle rectbmp = new Rectangle(0, 0, m_pBkgdBitmap.Width, m_pBkgdBitmap.Height);
using (System.Drawing.Bitmap pBmpMask =
m_pBkgdBitmap.Clone(rectbmp, PixelFormat.Format32bppArgb))
{
using (System.Drawing.Bitmap pBmpFontBodyBackup =
m_pBkgdBitmap.Clone(rectbmp, PixelFormat.Format32bppArgb))
{
using (System.Drawing.Graphics graphicsMask = System.Drawing.Graphics.FromImage(pBmpMask))
{
using (System.Drawing.SolidBrush brushBlack = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(0, 0, 0)))
{
graphicsMask.FillRectangle(brushBlack, 0, 0, m_pBkgdBitmap.Width, m_pBkgdBitmap.Height);
using (System.Drawing.Bitmap pBmpDisplay =
m_pBkgdBitmap.Clone(rectbmp, PixelFormat.Format32bppArgb))
{
using (System.Drawing.Graphics graphicsBkgd = System.Drawing.Graphics.FromImage(pBmpDisplay))
{
graphicsMask.CompositingMode = graphics.CompositingMode;
graphicsMask.CompositingQuality = graphics.CompositingQuality;
graphicsMask.InterpolationMode = graphics.InterpolationMode;
graphicsMask.SmoothingMode = graphics.SmoothingMode;
graphicsMask.TextRenderingHint = graphics.TextRenderingHint;
graphicsMask.PageUnit = graphics.PageUnit;
graphicsMask.PageScale = graphics.PageScale;
graphicsBkgd.CompositingMode = graphics.CompositingMode;
graphicsBkgd.CompositingQuality = graphics.CompositingQuality;
graphicsBkgd.InterpolationMode = graphics.InterpolationMode;
graphicsBkgd.SmoothingMode = graphics.SmoothingMode;
graphicsBkgd.TextRenderingHint = graphics.TextRenderingHint;
graphicsBkgd.PageUnit = graphics.PageUnit;
graphicsBkgd.PageScale = graphics.PageScale;
m_pFontBodyShadow.DrawString(
graphicsMask,
fontFamily,
fontStyle,
nfontSize,
strText,
ptDraw,
strFormat);
m_pShadowStrategy.DrawString(
graphicsBkgd,
fontFamily,
fontStyle,
nfontSize,
strText,
ptDraw,
strFormat);
unsafe
{
UInt32* pixelsSrc = null;
UInt32* pixelsDest = null;
UInt32* pixelsMask = null;
BitmapData bitmapDataSrc = new BitmapData();
BitmapData bitmapDataDest = new BitmapData();
BitmapData bitmapDataMask = new BitmapData();
Rectangle rect = new Rectangle(0, 0, m_pBkgdBitmap.Width, m_pBkgdBitmap.Height);
pBmpFontBodyBackup.LockBits(
rect,
ImageLockMode.WriteOnly,
PixelFormat.Format32bppArgb,
bitmapDataSrc);
pBmpDisplay.LockBits(
rect,
ImageLockMode.WriteOnly,
PixelFormat.Format32bppArgb,
bitmapDataDest);
pBmpMask.LockBits(
rect,
ImageLockMode.WriteOnly,
PixelFormat.Format32bppArgb,
bitmapDataMask);
// Write to the temporary buffer provided by LockBits.
pixelsSrc = (UInt32*)(bitmapDataSrc.Scan0);
pixelsDest = (UInt32*)(bitmapDataDest.Scan0);
pixelsMask = (UInt32*)(bitmapDataMask.Scan0);
if (pixelsSrc == null || pixelsDest == null || pixelsMask == null)
return;
UInt32 col = 0;
int stride = bitmapDataDest.Stride >> 2;
if (m_bDiffuseShadow && m_bExtrudeShadow == false)
{
for (UInt32 row = 0; row < bitmapDataDest.Height; ++row)
{
for (col = 0; col < bitmapDataDest.Width; ++col)
{
UInt32 index = (UInt32)(row * stride + col);
Byte nAlpha = (Byte)(pixelsMask[index] & 0xff);
UInt32 clrShadow = (UInt32)(0xff000000 | m_clrShadow.R << 16 | m_clrShadow.G << 8 | m_clrShadow.B);
if (nAlpha > 0)
{
UInt32 clrtotal = clrShadow;
for (int i = 2; i <= m_nShadowThickness; ++i)
pixelsSrc[index] = Alphablend(pixelsSrc[index], clrtotal, m_clrShadow.A);
pixelsDest[index] = pixelsSrc[index];
}
}
}
}
else
{
for (UInt32 row = 0; row < bitmapDataDest.Height; ++row)
{
for (col = 0; col < bitmapDataDest.Width; ++col)
{
UInt32 index = (UInt32)(row * stride + col);
Byte nAlpha = (Byte)(pixelsMask[index] & 0xff);
UInt32 clrShadow = (UInt32)(0xff000000 | m_clrShadow.R << 16 | m_clrShadow.G << 8 | m_clrShadow.B);
if (nAlpha > 0)
pixelsDest[index] = Alphablend(pixelsSrc[index], clrShadow, m_clrShadow.A);
}
}
}
pBmpMask.UnlockBits(bitmapDataMask);
pBmpDisplay.UnlockBits(bitmapDataDest);
pBmpFontBodyBackup.UnlockBits(bitmapDataSrc);
graphics.DrawImage(pBmpDisplay, 0, 0, pBmpDisplay.Width, pBmpDisplay.Height);
}
}
}
}
}
}
}
}
void RenderFontShadow(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int nfontSize,
string pszText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat)
{
Rectangle rectbmp = new Rectangle(0, 0, m_pBkgdBitmap.Width, m_pBkgdBitmap.Height);
using (System.Drawing.Bitmap pBmpMask =
m_pBkgdBitmap.Clone(rectbmp, PixelFormat.Format32bppArgb))
{
using (System.Drawing.Bitmap pBmpFontBodyBackup =
m_pBkgdBitmap.Clone(rectbmp, PixelFormat.Format32bppArgb))
{
using (System.Drawing.Graphics graphicsMask = System.Drawing.Graphics.FromImage(pBmpMask))
{
using (System.Drawing.SolidBrush brushBlack = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(0, 0, 0)))
{
graphicsMask.FillRectangle(brushBlack, 0, 0, m_pBkgdBitmap.Width, m_pBkgdBitmap.Height);
using (System.Drawing.Bitmap pBmpDisplay =
m_pBkgdBitmap.Clone(rectbmp, PixelFormat.Format32bppArgb))
{
using (System.Drawing.Graphics graphicsBkgd = System.Drawing.Graphics.FromImage(pBmpDisplay))
{
graphicsMask.CompositingMode = graphics.CompositingMode;
graphicsMask.CompositingQuality = graphics.CompositingQuality;
graphicsMask.InterpolationMode = graphics.InterpolationMode;
graphicsMask.SmoothingMode = graphics.SmoothingMode;
graphicsMask.TextRenderingHint = graphics.TextRenderingHint;
graphicsMask.PageUnit = graphics.PageUnit;
graphicsMask.PageScale = graphics.PageScale;
graphicsBkgd.CompositingMode = graphics.CompositingMode;
graphicsBkgd.CompositingQuality = graphics.CompositingQuality;
graphicsBkgd.InterpolationMode = graphics.InterpolationMode;
graphicsBkgd.SmoothingMode = graphics.SmoothingMode;
graphicsBkgd.TextRenderingHint = graphics.TextRenderingHint;
graphicsBkgd.PageUnit = graphics.PageUnit;
graphicsBkgd.PageScale = graphics.PageScale;
m_pFontBodyShadow.DrawString(
graphicsMask,
fontFamily,
fontStyle,
nfontSize,
pszText,
rtDraw,
strFormat);
m_pShadowStrategy.DrawString(
graphicsBkgd,
fontFamily,
fontStyle,
nfontSize,
pszText,
rtDraw,
strFormat);
unsafe
{
UInt32* pixelsSrc = null;
UInt32* pixelsDest = null;
UInt32* pixelsMask = null;
BitmapData bitmapDataSrc = new BitmapData();
BitmapData bitmapDataDest = new BitmapData();
BitmapData bitmapDataMask = new BitmapData();
Rectangle rect = new Rectangle(0, 0, m_pBkgdBitmap.Width, m_pBkgdBitmap.Height);
pBmpFontBodyBackup.LockBits(
rect,
ImageLockMode.WriteOnly,
PixelFormat.Format32bppArgb,
bitmapDataSrc);
pBmpDisplay.LockBits(
rect,
ImageLockMode.WriteOnly,
PixelFormat.Format32bppArgb,
bitmapDataDest);
pBmpMask.LockBits(
rect,
ImageLockMode.WriteOnly,
PixelFormat.Format32bppArgb,
bitmapDataMask);
// Write to the temporary buffer provided by LockBits.
pixelsSrc = (UInt32*)(bitmapDataSrc.Scan0);
pixelsDest = (UInt32*)(bitmapDataDest.Scan0);
pixelsMask = (UInt32*)(bitmapDataMask.Scan0);
if (pixelsSrc == null || pixelsDest == null || pixelsMask == null)
return;
UInt32 col = 0;
int stride = bitmapDataDest.Stride >> 2;
if (m_bDiffuseShadow && m_bExtrudeShadow == false)
{
for (UInt32 row = 0; row < bitmapDataDest.Height; ++row)
{
for (col = 0; col < bitmapDataDest.Width; ++col)
{
UInt32 index = (UInt32)(row * stride + col);
Byte nAlpha = (Byte)(pixelsMask[index] & 0xff);
UInt32 clrShadow = (UInt32)(0xff000000 | m_clrShadow.R << 16 | m_clrShadow.G << 8 | m_clrShadow.B);
if (nAlpha > 0)
{
UInt32 clrtotal = clrShadow;
for (int i = 2; i <= m_nShadowThickness; ++i)
pixelsSrc[index] = Alphablend(pixelsSrc[index], clrtotal, m_clrShadow.A);
pixelsDest[index] = pixelsSrc[index];
}
}
}
}
else
{
for (UInt32 row = 0; row < bitmapDataDest.Height; ++row)
{
for (col = 0; col < bitmapDataDest.Width; ++col)
{
UInt32 index = (UInt32)(row * stride + col);
Byte nAlpha = (Byte)(pixelsMask[index] & 0xff);
UInt32 clrShadow = (UInt32)(0xff000000 | m_clrShadow.R << 16 | m_clrShadow.G << 8 | m_clrShadow.B);
if (nAlpha > 0)
pixelsDest[index] = Alphablend(pixelsSrc[index], clrShadow, m_clrShadow.A);
}
}
}
pBmpMask.UnlockBits(bitmapDataMask);
pBmpDisplay.UnlockBits(bitmapDataDest);
pBmpFontBodyBackup.UnlockBits(bitmapDataSrc);
graphics.DrawImage(pBmpDisplay, 0, 0, pBmpDisplay.Width, pBmpDisplay.Height);
}
}
}
}
}
}
}
}
UInt32 Alphablend(UInt32 dest, UInt32 source, Byte nAlpha)
{
if( 0 == nAlpha )
return dest;
if( 255 == nAlpha )
return source;
Byte nInvAlpha = (Byte)(~nAlpha);
Byte nSrcRed = (Byte)((source & 0xff0000) >> 16);
Byte nSrcGreen = (Byte)((source & 0xff00) >> 8);
Byte nSrcBlue = (Byte)((source & 0xff));
Byte nDestRed = (Byte)((dest & 0xff0000) >> 16);
Byte nDestGreen = (Byte)((dest & 0xff00) >> 8);
Byte nDestBlue = (Byte)(dest & 0xff);
Byte nRed = (Byte)((nSrcRed * nAlpha + nDestRed * nInvAlpha) >> 8);
Byte nGreen = (Byte)((nSrcGreen * nAlpha + nDestGreen * nInvAlpha) >> 8);
Byte nBlue = (Byte)((nSrcBlue * nAlpha + nDestBlue * nInvAlpha) >> 8);
return (UInt32)(0xff000000 | nRed << 16 | nGreen << 8 | nBlue);
}
protected ITextStrategy m_pTextStrategy;
protected ITextStrategy m_pShadowStrategy;
protected ITextStrategy m_pFontBodyShadow;
protected System.Drawing.Point m_ptShadowOffset;
protected System.Drawing.Color m_clrShadow;
protected System.Drawing.Bitmap m_pBkgdBitmap;
protected bool m_bEnableShadow;
protected bool m_bDiffuseShadow;
protected int m_nShadowThickness;
protected bool m_bExtrudeShadow;
protected bool disposed;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TextDesignerCSLibrary")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TextDesignerCSLibrary")]
[assembly: AssemblyCopyright("Copyright © 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("69651077-2a6f-4c44-83f0-28518170f660")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,250 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace TextDesignerCSLibrary
{
public class TextDblGlowStrategy : ITextStrategy
{
public TextDblGlowStrategy()
{
m_nThickness1=2;
m_nThickness2=2;
m_brushText = null;
m_bClrText = true;
disposed = false;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
}
disposed = true;
}
}
~TextDblGlowStrategy()
{
Dispose(false);
}
public ITextStrategy Clone()
{
TextDblGlowStrategy p = new TextDblGlowStrategy();
if (m_bClrText)
p.Init(m_clrText, m_clrOutline1, m_clrOutline2, m_nThickness1, m_nThickness2);
else
p.Init(m_brushText, m_clrOutline1, m_clrOutline2, m_nThickness1, m_nThickness2);
return (ITextStrategy)(p);
}
public void Init(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness1,
int nThickness2 )
{
m_clrText = clrText;
m_bClrText = true;
m_clrOutline1 = clrOutline1;
m_clrOutline2 = clrOutline2;
m_nThickness1 = nThickness1;
m_nThickness2 = nThickness2;
}
public void Init(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness1,
int nThickness2)
{
m_brushText = brushText;
m_bClrText = false;
m_clrOutline1 = clrOutline1;
m_clrOutline2 = clrOutline2;
m_nThickness1 = nThickness1;
m_nThickness2 = nThickness2;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
for (int i = m_nThickness1; i <= m_nThickness1 + m_nThickness2; ++i)
{
using (Pen pen = new Pen(m_clrOutline2, i))
{
pen.LineJoin = LineJoin.Round;
graphics.DrawPath(pen, path);
}
}
using (Pen pen1 = new Pen(m_clrOutline1, m_nThickness1))
{
pen1.LineJoin = LineJoin.Round;
graphics.DrawPath(pen1, path);
}
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
return true;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
for (int i = m_nThickness1; i <= m_nThickness1 + m_nThickness2; ++i)
{
using (Pen pen = new Pen(m_clrOutline2, i))
{
pen.LineJoin = LineJoin.Round;
graphics.DrawPath(pen, path);
}
}
using (Pen pen1 = new Pen(m_clrOutline1, m_nThickness1))
{
pen1.LineJoin = LineJoin.Round;
graphics.DrawPath(pen1, path);
}
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
fDestWidth = ptDraw.X;
fDestHeight = ptDraw.Y;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness1 + m_nThickness2, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
fDestWidth = rtDraw.Width;
fDestHeight = rtDraw.Height;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness1 + m_nThickness2, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
protected System.Drawing.Color m_clrText;
protected System.Drawing.Color m_clrOutline1;
protected System.Drawing.Color m_clrOutline2;
protected int m_nThickness1;
protected int m_nThickness2;
protected System.Drawing.Brush m_brushText;
protected bool m_bClrText;
protected bool disposed;
}
}

View File

@@ -0,0 +1,244 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace TextDesignerCSLibrary
{
public class TextDblOutlineStrategy : ITextStrategy
{
public TextDblOutlineStrategy()
{
m_nThickness1=2;
m_nThickness2=2;
m_brushText = null;
m_bClrText = true;
disposed = false;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
}
disposed = true;
}
}
~TextDblOutlineStrategy()
{
Dispose(false);
}
public ITextStrategy Clone()
{
TextDblOutlineStrategy p = new TextDblOutlineStrategy();
if (m_bClrText)
p.Init(m_clrText, m_clrOutline1, m_clrOutline2, m_nThickness1, m_nThickness2);
else
p.Init(m_brushText, m_clrOutline1, m_clrOutline2, m_nThickness1, m_nThickness2);
return (ITextStrategy)(p);
}
public void Init(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness1,
int nThickness2 )
{
m_clrText = clrText;
m_bClrText = true;
m_clrOutline1 = clrOutline1;
m_clrOutline2 = clrOutline2;
m_nThickness1 = nThickness1;
m_nThickness2 = nThickness2;
}
public void Init(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness1,
int nThickness2)
{
m_brushText = brushText;
m_bClrText = false;
m_clrOutline1 = clrOutline1;
m_clrOutline2 = clrOutline2;
m_nThickness1 = nThickness1;
m_nThickness2 = nThickness2;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
using (Pen pen2 = new Pen(m_clrOutline2, m_nThickness1 + m_nThickness2))
{
pen2.LineJoin = LineJoin.Round;
graphics.DrawPath(pen2, path);
}
using (Pen pen1 = new Pen(m_clrOutline1, m_nThickness1))
{
pen1.LineJoin = LineJoin.Round;
graphics.DrawPath(pen1, path);
}
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
return true;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
using (Pen pen2 = new Pen(m_clrOutline2, m_nThickness1 + m_nThickness2))
{
pen2.LineJoin = LineJoin.Round;
graphics.DrawPath(pen2, path);
}
using (Pen pen1 = new Pen(m_clrOutline1, m_nThickness1))
{
pen1.LineJoin = LineJoin.Round;
graphics.DrawPath(pen1, path);
}
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
fDestWidth = ptDraw.X;
fDestHeight = ptDraw.Y;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness1 + m_nThickness2, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
fDestWidth = rtDraw.Width;
fDestHeight = rtDraw.Height;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness1 + m_nThickness2, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
protected System.Drawing.Color m_clrText;
protected System.Drawing.Color m_clrOutline1;
protected System.Drawing.Color m_clrOutline2;
protected int m_nThickness1;
protected int m_nThickness2;
protected System.Drawing.Brush m_brushText;
protected bool m_bClrText;
protected bool disposed;
}
}

View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{43967937-3D38-4DD8-9C63-A486A0BB6DD5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TextDesignerCSLibrary</RootNamespace>
<AssemblyName>TextDesignerCSLibrary</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BmpOutlineText.cs" />
<Compile Include="DiffusedShadowStrategy.cs" />
<Compile Include="DrawGradient.cs" />
<Compile Include="ExtrudeStrategy.cs" />
<Compile Include="GDIPath.cs" />
<Compile Include="IOutlineText.cs" />
<Compile Include="ITextStrategy.cs" />
<Compile Include="OutlineText.cs" />
<Compile Include="PngOutlineText.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TextDblGlowStrategy.cs" />
<Compile Include="TextDblOutlineStrategy.cs" />
<Compile Include="TextGlowStrategy.cs" />
<Compile Include="TextGradOutlineStrategy.cs" />
<Compile Include="TextNoOutlineStrategy.cs" />
<Compile Include="TextOnlyOutlineStrategy.cs" />
<Compile Include="TextOutlineStrategy.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{43967937-3D38-4DD8-9C63-A486A0BB6DD5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TextDesignerCSLibrary</RootNamespace>
<AssemblyName>TextDesignerCSLibrary</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BmpOutlineText.cs" />
<Compile Include="Canvas.cs" />
<Compile Include="DiffusedShadowStrategy.cs" />
<Compile Include="DrawGradient.cs" />
<Compile Include="ExtrudeStrategy.cs" />
<Compile Include="GDIPath.cs" />
<Compile Include="IOutlineText.cs" />
<Compile Include="ITextStrategy.cs" />
<Compile Include="MaskColor.cs" />
<Compile Include="OutlineText.cs" />
<Compile Include="PngOutlineText.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TextDblGlowStrategy.cs" />
<Compile Include="TextDblOutlineStrategy.cs" />
<Compile Include="TextGlowStrategy.cs" />
<Compile Include="TextGradOutlineStrategy.cs" />
<Compile Include="TextNoOutlineStrategy.cs" />
<Compile Include="TextOnlyOutlineStrategy.cs" />
<Compile Include="TextOutlineStrategy.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,230 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace TextDesignerCSLibrary
{
class TextGlowStrategy : ITextStrategy
{
public TextGlowStrategy()
{
m_nThickness=2;
m_brushText = null;
m_bClrText = true;
disposed = false;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
}
disposed = true;
}
}
~TextGlowStrategy()
{
Dispose(false);
}
public ITextStrategy Clone()
{
TextGlowStrategy p = new TextGlowStrategy();
if (m_bClrText)
p.Init(m_clrText, m_clrOutline, m_nThickness);
else
p.Init(m_brushText, m_clrOutline, m_nThickness);
return (ITextStrategy)(p);
}
public void Init(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline,
int nThickness )
{
m_clrText = clrText;
m_bClrText = true;
m_clrOutline = clrOutline;
m_nThickness = nThickness;
}
public void Init(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline,
int nThickness)
{
m_brushText = brushText;
m_bClrText = false;
m_clrOutline = clrOutline;
m_nThickness = nThickness;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
for (int i = 1; i <= m_nThickness; ++i)
{
using (Pen pen = new Pen(m_clrOutline, i))
{
pen.LineJoin = LineJoin.Round;
graphics.DrawPath(pen, path);
}
}
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
return true;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
for (int i = 1; i <= m_nThickness; ++i)
{
using (Pen pen = new Pen(m_clrOutline, i))
{
pen.LineJoin = LineJoin.Round;
graphics.DrawPath(pen, path);
}
}
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
fDestWidth = ptDraw.X;
fDestHeight = ptDraw.Y;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
fDestWidth = rtDraw.Width;
fDestHeight = rtDraw.Height;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
protected System.Drawing.Color m_clrText;
protected System.Drawing.Color m_clrOutline;
protected int m_nThickness;
protected System.Drawing.Brush m_brushText;
protected bool m_bClrText;
protected bool disposed;
}
}

View File

@@ -0,0 +1,304 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace TextDesignerCSLibrary
{
public class TextGradOutlineStrategy : ITextStrategy
{
public TextGradOutlineStrategy()
{
m_nThickness=2;
m_brushText = null;
m_bClrText = true;
disposed = false;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
}
disposed = true;
}
}
~TextGradOutlineStrategy()
{
Dispose(false);
}
public ITextStrategy Clone()
{
TextGradOutlineStrategy p = new TextGradOutlineStrategy();
if (m_bClrText)
p.Init(m_clrText, m_clrOutline1, m_clrOutline2, m_nThickness);
else
p.Init(m_brushText, m_clrOutline1, m_clrOutline2, m_nThickness);
return (ITextStrategy)(p);
}
public void Init(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness )
{
m_clrText = clrText;
m_bClrText = true;
m_clrOutline1 = clrOutline1;
m_clrOutline2 = clrOutline2;
m_nThickness = nThickness;
}
public void Init(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline1,
System.Drawing.Color clrOutline2,
int nThickness)
{
m_brushText = brushText;
m_bClrText = false;
m_clrOutline1 = clrOutline1;
m_clrOutline2 = clrOutline2;
m_nThickness = nThickness;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
List<Color> list = new List<Color>();
CalculateGradient(
m_clrOutline1,
m_clrOutline2,
m_nThickness,
list);
for (int i = m_nThickness; i >= 1; --i)
{
using (Pen pen1 = new Pen(list[i - 1], i))
{
pen1.LineJoin = LineJoin.Round;
graphics.DrawPath(pen1, path);
}
}
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
return true;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
List<Color> list = new List<Color>();
CalculateGradient(
m_clrOutline1,
m_clrOutline2,
m_nThickness,
list);
for (int i = m_nThickness; i >= 1; --i)
{
using (Pen pen1 = new Pen(list[i - 1], i))
{
pen1.LineJoin = LineJoin.Round;
graphics.DrawPath(pen1, path);
}
}
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
fDestWidth = ptDraw.X;
fDestHeight = ptDraw.Y;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
fDestWidth = rtDraw.Width;
fDestHeight = rtDraw.Height;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
void CalculateGradient(
Color clr1,
Color clr2,
int nThickness,
List<Color> list)
{
list.Clear();
int nWidth = nThickness;
int nHeight = 1;
Rectangle rect = new Rectangle(0, 0, nWidth, nHeight);
LinearGradientBrush brush = new LinearGradientBrush(rect,
clr1, clr2, LinearGradientMode.Horizontal);
using (Bitmap pImage = new Bitmap(nWidth, nHeight, PixelFormat.Format32bppArgb))
{
using (Graphics graphics = System.Drawing.Graphics.FromImage(pImage))
{
graphics.FillRectangle(brush, 0, 0, pImage.Width, pImage.Height);
BitmapData bitmapData = new BitmapData();
pImage.LockBits(
rect,
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb,
bitmapData);
unsafe
{
uint* pixels = (uint*)bitmapData.Scan0;
if (pixels == null)
{
pImage.UnlockBits(bitmapData);
return;
}
uint col = 0;
int stride = bitmapData.Stride >> 2;
for (uint row = 0; row < bitmapData.Height; ++row)
{
for (col = 0; col < bitmapData.Width; ++col)
{
uint index = (uint)(row * stride + col);
uint color = pixels[index];
Color gdiColor = Color.FromArgb((int)((color & 0xff0000) >> 16), (int)((color & 0xff00) >> 8), (int)(color & 0xff));
list.Add(gdiColor);
}
}
}
pImage.UnlockBits(bitmapData);
}
}
}
protected System.Drawing.Color m_clrText;
protected System.Drawing.Color m_clrOutline1;
protected System.Drawing.Color m_clrOutline2;
protected int m_nThickness;
protected System.Drawing.Brush m_brushText;
protected bool m_bClrText;
protected bool disposed;
}
}

View File

@@ -0,0 +1,170 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace TextDesignerCSLibrary
{
public class TextNoOutlineStrategy : ITextStrategy
{
public TextNoOutlineStrategy()
{
m_brushText = null;
m_bClrText = true;
disposed = false;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
}
disposed = true;
}
}
~TextNoOutlineStrategy()
{
Dispose(false);
}
public ITextStrategy Clone()
{
TextNoOutlineStrategy p = new TextNoOutlineStrategy();
if (m_bClrText)
p.Init(m_clrText);
else
p.Init(m_brushText);
return (ITextStrategy)(p);
}
public void Init(
System.Drawing.Color clrText)
{
m_clrText = clrText;
m_bClrText = true;
}
public void Init(
System.Drawing.Brush brushText)
{
m_brushText = brushText;
m_bClrText = false;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
return true;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
fDestWidth = ptDraw.X;
fDestHeight = ptDraw.Y;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
return b;
}
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
fDestWidth = rtDraw.Width;
fDestHeight = rtDraw.Height;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
return b;
}
}
protected System.Drawing.Color m_clrText;
protected System.Drawing.Brush m_brushText;
protected bool m_bClrText;
protected bool disposed;
}
}

View File

@@ -0,0 +1,188 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace TextDesignerCSLibrary
{
public class TextOnlyOutlineStrategy : ITextStrategy
{
public TextOnlyOutlineStrategy()
{
m_nThickness=2;
m_bRoundedEdge = false;
disposed = false;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
}
disposed = true;
}
}
~TextOnlyOutlineStrategy()
{
Dispose(false);
}
public ITextStrategy Clone()
{
TextOnlyOutlineStrategy p = new TextOnlyOutlineStrategy();
p.Init(m_clrOutline, m_nThickness, m_bRoundedEdge);
return (ITextStrategy)(p);
}
public void Init(
System.Drawing.Color clrOutline,
int nThickness,
bool bRoundedEdge)
{
m_clrOutline = clrOutline;
m_nThickness = nThickness;
m_bRoundedEdge = bRoundedEdge;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
using (Pen pen = new Pen(m_clrOutline, m_nThickness))
{
pen.LineJoin = LineJoin.Round;
graphics.DrawPath(pen, path);
}
}
return true;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
using (Pen pen = new Pen(m_clrOutline, m_nThickness))
{
pen.LineJoin = LineJoin.Round;
graphics.DrawPath(pen, path);
}
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
fDestWidth = ptDraw.X;
fDestHeight = ptDraw.Y;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
fDestWidth = rtDraw.Width;
fDestHeight = rtDraw.Height;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
protected System.Drawing.Color m_clrOutline;
protected int m_nThickness;
protected bool m_bClrText;
protected bool m_bRoundedEdge;
protected bool disposed;
}
}

View File

@@ -0,0 +1,225 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace TextDesignerCSLibrary
{
public class TextOutlineStrategy : ITextStrategy
{
public TextOutlineStrategy()
{
m_nThickness=2;
m_brushText = null;
m_bClrText = true;
disposed = false;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
}
disposed = true;
}
}
~TextOutlineStrategy()
{
Dispose(false);
}
public ITextStrategy Clone()
{
TextOutlineStrategy p = new TextOutlineStrategy();
if (m_bClrText)
p.Init(m_clrText, m_clrOutline, m_nThickness);
else
p.Init(m_brushText, m_clrOutline, m_nThickness);
return (ITextStrategy)(p);
}
public void Init(
System.Drawing.Color clrText,
System.Drawing.Color clrOutline,
int nThickness )
{
m_clrText = clrText;
m_bClrText = true;
m_clrOutline = clrOutline;
m_nThickness = nThickness;
}
public void Init(
System.Drawing.Brush brushText,
System.Drawing.Color clrOutline,
int nThickness)
{
m_brushText = brushText;
m_bClrText = false;
m_clrOutline = clrOutline;
m_nThickness = nThickness;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
using (Pen pen = new Pen(m_clrOutline, m_nThickness))
{
pen.LineJoin = LineJoin.Round;
graphics.DrawPath(pen, path);
}
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
return true;
}
public bool DrawString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
using (Pen pen = new Pen(m_clrOutline, m_nThickness))
{
pen.LineJoin = LineJoin.Round;
graphics.DrawPath(pen, path);
}
if (m_bClrText)
{
using (SolidBrush brush = new SolidBrush(m_clrText))
{
graphics.FillPath(brush, path);
}
}
else
graphics.FillPath(m_brushText, path);
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Point ptDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);
fDestWidth = ptDraw.X;
fDestHeight = ptDraw.Y;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
public bool MeasureString(
System.Drawing.Graphics graphics,
System.Drawing.FontFamily fontFamily,
System.Drawing.FontStyle fontStyle,
int fontSize,
string strText,
System.Drawing.Rectangle rtDraw,
System.Drawing.StringFormat strFormat,
ref float fStartX,
ref float fStartY,
ref float fDestWidth,
ref float fDestHeight)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);
fDestWidth = rtDraw.Width;
fDestHeight = rtDraw.Height;
bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);
if (false == b)
return false;
float pixelThick = 0.0f;
float pixelThick2 = 0.0f;
float fStartX2 = 0.0f;
float fStartY2 = 0.0f;
b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);
if (false == b)
return false;
fDestWidth += pixelThick;
fDestHeight += pixelThick;
}
return true;
}
protected System.Drawing.Color m_clrText;
protected System.Drawing.Color m_clrOutline;
protected int m_nThickness;
protected System.Drawing.Brush m_brushText;
protected bool m_bClrText;
protected bool disposed;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

View File

@@ -0,0 +1,4 @@
D:\Calismalar\C#\TestOutlineText\TextDesignerCSLibrary\bin\Debug\TextDesignerCSLibrary.dll
D:\Calismalar\C#\TestOutlineText\TextDesignerCSLibrary\bin\Debug\TextDesignerCSLibrary.pdb
D:\Calismalar\C#\TestOutlineText\TextDesignerCSLibrary\obj\Debug\TextDesignerCSLibrary.dll
D:\Calismalar\C#\TestOutlineText\TextDesignerCSLibrary\obj\Debug\TextDesignerCSLibrary.pdb

View File

@@ -0,0 +1,4 @@
D:\Calismalar\C#\TestOutlineText\TextDesignerCSLibrary\bin\Debug\TextDesignerCSLibrary.dll
D:\Calismalar\C#\TestOutlineText\TextDesignerCSLibrary\bin\Debug\TextDesignerCSLibrary.pdb
D:\Calismalar\C#\TestOutlineText\TextDesignerCSLibrary\obj\Debug\TextDesignerCSLibrary.dll
D:\Calismalar\C#\TestOutlineText\TextDesignerCSLibrary\obj\Debug\TextDesignerCSLibrary.pdb