本文整理汇总了C#中Cairo.Context.SetFontSize方法的典型用法代码示例。如果您正苦于以下问题:C# Context.SetFontSize方法的具体用法?C# Context.SetFontSize怎么用?C# Context.SetFontSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cairo.Context
的用法示例。
在下文中一共展示了Context.SetFontSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Image_Loaded
private void Image_Loaded(object sender, RoutedEventArgs e)
{
Image image = (Image)sender;
using (ImageSurface surface = new ImageSurface(Format.Argb32, (int)image.Width, (int)image.Height))
{
using (Context context = new Context(surface))
{
PointD p = new PointD(10.0, 10.0);
PointD p2 = new PointD(100.0, 10.0);
PointD p3 = new PointD(100.0, 100.0);
PointD p4 = new PointD(10.0, 100.0);
context.MoveTo(p);
context.LineTo(p2);
context.LineTo(p3);
context.LineTo(p4);
context.LineTo(p);
context.ClosePath();
context.Fill();
context.MoveTo(140.0, 110.0);
context.SetFontSize(32.0);
context.SetSourceColor(new Color(0.0, 0.0, 0.8, 1.0));
context.ShowText("Hello Cairo!");
surface.Flush();
RgbaBitmapSource source = new RgbaBitmapSource(surface.Data, surface.Width);
image.Source = source;
}
}
}
示例2: DrawGraph
public void DrawGraph(Context gr)
{
int mag = Magnification;
double xoffset = (Allocation.Width/2) ;
double yoffset = (Allocation.Height/2) ;
if (ForceGraph != null) {
this.GdkWindow.Clear ();
gr.Antialias = Antialias.Subpixel;
foreach (var p in ForceGraph.Springs){
gr.LineWidth = 1.5;
if ( p.Data != null ){
var data = p.Data as NodeData;
if ( data != null )
gr.Color = data.Stroke;
} else {
gr.Color = new Color( 0,0,0,1);
}
gr.MoveTo( xoffset + ( p.NodeA.Location.X * mag ), yoffset + ( p.NodeA.Location.Y * mag ) );
gr.LineTo( xoffset + ( p.NodeB.Location.X * mag ), yoffset + ( p.NodeB.Location.Y * mag ) );
gr.Stroke();
}
foreach (var n in ForceGraph.Nodes) {
var stroke = new Color( 0.1, 0.1, 0.1, 0.8 );
var fill = new Color( 0.2, 0.7, 0.7, 0.8 );
var size = 5.5;
NodeData nd = n.Data as NodeData;
if ( nd != null ){
stroke = nd.Stroke;
fill = nd.Fill;
size = nd.Size;
}
DrawFilledCircle (gr,
xoffset + (mag * n.Location.X),
yoffset + (mag * n.Location.Y),
size,
stroke,
fill
);
if ( nd != null ) {
if ( nd.Label != null ){
gr.Color = new Color(0,0,0,0.7);
gr.SetFontSize(24);
gr.MoveTo( 25 + xoffset + (mag * n.Location.X), 25 + yoffset + (mag * n.Location.Y));
gr.ShowText( nd.Label );
}
}
}
}
}
示例3: CreatePng
public void CreatePng ()
{
const int Width = 480;
const int Height = 160;
const int CheckSize = 10;
const int Spacing = 2;
// Create an Image-based surface with data stored in ARGB32 format and a context,
// "using" is used here to ensure that they are Disposed once we are done
using (ImageSurface surface = new ImageSurface (Format.ARGB32, Width, Height))
using (Context cr = new Cairo.Context (surface))
{
// Start drawing a checkerboard
int i, j, xcount, ycount;
xcount = 0;
i = Spacing;
while (i < Width) {
j = Spacing;
ycount = xcount % 2; // start with even/odd depending on row
while (j < Height) {
if (ycount % 2 != 0)
cr.SetSourceRGB (1, 0, 0);
else
cr.SetSourceRGB (1, 1, 1);
// If we're outside the clip, this will do nothing.
cr.Rectangle (i, j, CheckSize, CheckSize);
cr.Fill ();
j += CheckSize + Spacing;
++ycount;
}
i += CheckSize + Spacing;
++xcount;
}
// Select a font to draw with
cr.SelectFontFace ("serif", FontSlant.Normal, FontWeight.Bold);
cr.SetFontSize (64.0);
// Select a color (blue)
cr.SetSourceRGB (0, 0, 1);
// Draw
cr.MoveTo (20, 100);
cr.ShowText ("Hello, World");
surface.WriteToPng ("test.png");
}
}
示例4: OnExposed
protected override bool OnExposed(Context cr, Rectangle area)
{
cr.Save();
if(!base.OnExposed(cr, area))
{
cr.Color = new Color(1.0, 0.0, 0.0);
cr.SetFontSize(100.0);
cr.SelectFontFace("Librarian", FontSlant.Normal, FontWeight.Bold);
cr.ShowText(role.ToString());
cr.Restore();
return true;
}
cr.Restore();
return true;
}
示例5: OnExposed
protected override bool OnExposed(Context cr, Rectangle area)
{
cr.Save();
if(!base.OnExposed(cr, area))
{
cr.Color = new Color(1.0, 0.0, 1.0);
cr.Rectangle(new Rectangle(2.0, 2.0, Allocation.Width - 4.0, Allocation.Height - 4.0));
cr.LineWidth = 4.0;
cr.LineJoin = LineJoin.Round;
cr.Stroke();
cr.SetFontSize(20.0);
cr.SelectFontFace("Librarian", FontSlant.Normal, FontWeight.Bold);
cr.Translate(0.0, Allocation.Height / 2);
cr.ShowText(type.ToString());
cr.Restore();
return true;
}
cr.Restore();
return true;
}
示例6: InternalRegenerateCloud
/*
[XmlIgnore]
public FontFamily font;
*/
public void InternalRegenerateCloud()
{
r = new Random();
int id = 0;
double minSize = Entries.Min(e => e.SizeValue);
double maxSize = Entries.Max(e => e.SizeValue);
double range = Math.Max(0.00001, maxSize - minSize);
_source = new ImageSurface(Format.Argb32,ActualWidth,ActualHeight);
pixelss = _source.Data;
g = new Context(_source);
g.Color = new Color(1.0,1.0,1.0);
//g.Rectangle(0.0,0.0,ActualWidth,ActualHeight);
g.Paint();
g.SelectFontFace(fontname,FontSlant.Normal,FontWeight.Bold);
g.SetFontSize(100.0);
TextExtents te = g.TextExtents("x");
double areaPerLetter = te.Width;
strides = _source.Stride;
int arraySize = (int)((ActualWidth / 4) + 2) * (int)((ActualHeight / 4) + 2);
_mapping = new int[arraySize];
for (int i = 0; i < arraySize; i++) _mapping[i] = -1;
if(svgfn != null) {
svgs = new SvgSurface(svgfn,ActualWidth,ActualHeight);
svg = new Context(svgs);
svg.SelectFontFace(fontname,FontSlant.Normal,FontWeight.Bold);
}
if(pdffn != null) {
pdfs = new PdfSurface(pdffn,ActualWidth,ActualHeight);
pdf = new Context(pdfs);
pdf.SelectFontFace(fontname,FontSlant.Normal,FontWeight.Bold);
}
double fontMultiplier;
if(CoverRatio > 0.0) {
double totalsize = 0.0;
MinFontSize = 24.0; // use big fonts for testing
if(FontMaxRatio < 1.0 || FontMaxRatio > 500.0) FontMaxRatio = 6.0;
MaxFontSize = FontMaxRatio*MinFontSize;
fontMultiplier = (MaxFontSize - MinFontSize) / range;
foreach(WordCloudEntry e in Entries) {
float fontsize = (float)(((e.SizeValue - minSize) * fontMultiplier) + MinFontSize);
g.SetFontSize(fontsize);
TextExtents te1 = g.TextExtents(e.Word);
totalsize += te1.Width*te1.Height;
}
double actualsize = ActualHeight*ActualWidth;
double ratio1 = totalsize / actualsize; //this should be == CoverRatio
//we assume that totalsize ~ MinFontSize^2 in this case
MinFontSize = MinFontSize*Math.Sqrt(CoverRatio / ratio1);
MaxFontSize = FontMaxRatio*MinFontSize;
fontMultiplier = (MaxFontSize - MinFontSize) / range;
LargestSizeWidthProportion = 0.9;
}
double targetWidth = Math.Max(ActualWidth, ActualHeight) * LargestSizeWidthProportion;
WordCloudEntry od = Entries.OrderByDescending(e => (e.SizeValue - minSize) * e.Word.Length).First();
double maxFontSize;
if(MaxFontSize > 0.0 && CoverRatio <= 0.0) {
maxFontSize = MaxFontSize;
if(maxFontSize < MinFontSize) maxFontSize = MinFontSize*2.7;
}
else {
g.SetFontSize(100.0);
TextExtents te2 = g.TextExtents(od.Word);
maxFontSize = 97.0*targetWidth / te2.Width;
//maxFontSize = Math.Max(MinFontSize * 2.7, 100.0 / ((od.Word.Length * areaPerLetter) / targetWidth));
if(maxFontSize > MinFontSize + 100) maxFontSize = MinFontSize + 100;
}
if(CoverRatio > 0.0) {
if(maxFontSize < MaxFontSize) MaxFontSize = maxFontSize;
fontMultiplier = (maxFontSize - MinFontSize) / range;
}
else fontMultiplier = (maxFontSize - MinFontSize) / range;
var points = new[]
{
new Point((int) (ActualWidth/2), (int) (ActualHeight/2)),
new Point((int) (ActualWidth/4), (int) (ActualHeight/4)),
new Point((int) (ActualWidth/4), (int) (3*ActualHeight/2)),
new Point((int) (3*ActualWidth/4), (int) (ActualHeight/2)),
new Point((int) (3*ActualWidth/4), (int) (3*ActualHeight/4))
};
int currentPoint = 0;
foreach (WordCloudEntry e in Entries.OrderByDescending(e => e.SizeValue))
{
again:
double position = 0.0;
Point centre = points[currentPoint];
double angle = 0.0;
//.........这里部分代码省略.........
示例7: onDraw
protected override void onDraw(Context gr)
{
base.onDraw (gr);
gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
gr.SetFontSize (Font.Size);
gr.FontOptions = Interface.FontRenderingOptions;
gr.Antialias = Interface.Antialias;
rText = new Rectangle(new Size(
measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height)));
rText.Width -= 2 * Margin;
rText.Height -= 2 * Margin;
widthRatio = 1f;
heightRatio = 1f;
Rectangle cb = ClientRectangle;
rText.X = cb.X;
rText.Y = cb.Y;
if (horizontalStretch) {
widthRatio = (float)cb.Width / (float)rText.Width;
if (!verticalStretch)
heightRatio = widthRatio;
}
if (verticalStretch) {
heightRatio = (float)cb.Height / (float)rText.Height;
if (!horizontalStretch)
widthRatio = heightRatio;
}
rText.Width = (int)(widthRatio * (float)rText.Width);
rText.Height = (int)(heightRatio * (float)rText.Height);
switch (TextAlignment)
{
case Alignment.TopLeft: //ok
rText.X = cb.X;
rText.Y = cb.Y;
break;
case Alignment.Top: //ok
rText.Y = cb.Y;
rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
break;
case Alignment.TopRight: //ok
rText.Y = cb.Y;
rText.X = cb.Right - rText.Width;
break;
case Alignment.Left://ok
rText.X = cb.X;
rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
break;
case Alignment.Right://ok
rText.X = cb.X + cb.Width - rText.Width;
rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
break;
case Alignment.Bottom://ok
rText.X = cb.Width / 2 - rText.Width / 2;
rText.Y = cb.Height - rText.Height;
break;
case Alignment.BottomLeft://ok
rText.X = cb.X;
rText.Y = cb.Bottom - rText.Height;
break;
case Alignment.BottomRight://ok
rText.Y = cb.Bottom - rText.Height;
rText.X = cb.Right - rText.Width;
break;
case Alignment.Center://ok
rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
break;
}
gr.FontMatrix = new Matrix(widthRatio * (float)Font.Size, 0, 0, heightRatio * (float)Font.Size, 0, 0);
fe = gr.FontExtents;
#region draw text cursor
if (HasFocus && Selectable)
{
if (mouseLocalPos >= 0)
{
computeTextCursor(gr);
if (SelectionInProgress)
{
if (SelBegin < 0){
SelBegin = new Point(CurrentColumn, CurrentLine);
SelStartCursorPos = textCursorPos;
SelRelease = -1;
}else{
SelRelease = new Point(CurrentColumn, CurrentLine);
if (SelRelease == SelBegin)
SelRelease = -1;
else
SelEndCursorPos = textCursorPos;
}
//.........这里部分代码省略.........
示例8: measureRawSize
protected override int measureRawSize(LayoutingType lt)
{
if (lines == null)
lines = getLines;
using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) {
using (Context gr = new Context (img)) {
//Cairo.FontFace cf = gr.GetContextFontFace ();
gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
gr.SetFontSize (Font.Size);
fe = gr.FontExtents;
te = new TextExtents();
if (lt == LayoutingType.Height){
int lc = lines.Count;
//ensure minimal height = text line height
if (lc == 0)
lc = 1;
return (int)Math.Ceiling(fe.Height * lc) + Margin * 2;
}
foreach (string s in lines) {
string l = s.Replace("\t", new String (' ', Interface.TabSize));
TextExtents tmp = gr.TextExtents (l);
if (tmp.XAdvance > te.XAdvance)
te = tmp;
}
return (int)Math.Ceiling (te.XAdvance) + Margin * 2;
}
}
}
示例9: text_extents
public void text_extents(Context cr, int width, int height)
{
double x=0.1;
double y=0.6;
string utf8 = "cairo";
Normalize (cr, width, height);
cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);
cr.SetFontSize(0.4);
TextExtents extents = cr.TextExtents(utf8);
cr.MoveTo(x,y);
cr.ShowText(utf8);
// draw helping lines
cr.Color = new Color (1, 0.2, 0.2, 0.6);
cr.Arc(x, y, 0.05, 0, 2*Math.PI);
cr.Fill();
cr.MoveTo(x,y);
cr.RelLineTo(0, -extents.Height);
cr.RelLineTo(extents.Width, 0);
cr.RelLineTo(extents.XBearing, -extents.YBearing);
cr.Stroke();
}
示例10: text_align_center
public void text_align_center(Context cr, int width, int height)
{
Normalize (cr, width, height);
cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);
cr.SetFontSize(0.2);
TextExtents extents = cr.TextExtents("cairo");
double x = 0.5 -((extents.Width/2.0) + extents.XBearing);
double y = 0.5 -((extents.Height/2.0) + extents.YBearing);
cr.MoveTo(x, y);
cr.ShowText("cairo");
// draw helping lines
cr.Color = new Color (1, 0.2, 0.2, 0.6);
cr.Arc(x, y, 0.05, 0, 2*Math.PI);
cr.Fill();
cr.MoveTo(0.5, 0);
cr.RelLineTo(0, 1);
cr.MoveTo(0, 0.5);
cr.RelLineTo(1, 0);
cr.Stroke();
}
示例11: text
public void text(Context cr, int width, int height)
{
Normalize (cr, width, height);
cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Bold);
cr.SetFontSize(0.35);
cr.MoveTo(0.04, 0.53);
cr.ShowText("Hello");
cr.MoveTo(0.27, 0.65);
cr.TextPath("void");
cr.Save();
cr.Color = new Color (0.5,0.5,1);
cr.Fill();
cr.Restore();
cr.LineWidth = 0.01;
cr.Stroke();
// draw helping lines
cr.Color = new Color (1.0, 0.2, 0.2, 0.6);
cr.Arc(0.04, 0.53, 0.02, 0, 2*Math.PI);
cr.Arc(0.27, 0.65, 0.02, 0, 2*Math.PI);
cr.Fill();
}
示例12: PixbufText
private Pixbuf PixbufText(string text, int size, bool transparent)
{
int x=0, y=36;
surface = new Cairo.ImageSurface(Cairo.Format.Argb32, 800, 600);
cr = new Cairo.Context(surface);
if (!transparent) {
cr.SetSourceRGBA (0.0, 0.0, 0.0, 1.0);
cr.Rectangle (new Cairo.Rectangle (0, 0, 800, 600));
cr.Fill ();
}
//cr.MoveTo(x, y);
string font = "sans";
if (Util.IsWindows ()) {
font = "MS Gothic";
}
if (Util.IsLinux ()) {
font = "TakaoGothic";
}
if (Util.IsMac ()) {
font = "Hiragino Kaku Gothic ProN";
}
cr.SelectFontFace(font, Cairo.FontSlant.Normal, Cairo.FontWeight.Bold);
cr.SetFontSize(size);
Cairo.TextExtents extents = cr.TextExtents(text);
string[] lines = text.Split ('\n');
int min = size;
for (int i = 0; i < lines.Length; i++) {
string line = lines[i];
for (int j = size; j > 8; j-=4) {
extents = cr.TextExtents(line);
if(extents.Width+extents.XBearing<800){
if(j<min) min = j;
break;
}
cr.SetFontSize(j);
}
}
cr.SetFontSize(min);
//string[] lines = text.Split ('\n');
for (int i = 0; i < lines.Length; i++) {
DrawText (cr, lines[i], x, y);
y += (int)extents.Height;
if (i > 5)
break;
}
Pixbuf buf = new Gdk.Pixbuf (surface.Data, true, 8, surface.Width, surface.Height, surface.Stride);
return buf;
//buf.Save ("aaa.png", "png");
//surface.WriteToPng (file);
}
示例13: Draw
public static void Draw (Context grw, TextElement text)
{
double dY = 0;
if (text.Foregraund != null) {
grw.SetSourceRGB (
text.Foregraund.Red,
text.Foregraund.Green,
text.Foregraund.Blue);
}
grw.SelectFontFace (
text.FontFamily,
FontSlant.Normal,
(FontWeight)text.Weight);
grw.SetFontSize (text.ScaledFontSize);
var te = grw.TextExtents (text.Text);
double dX = 0;
if (text.Align != null) {
switch (text.Align.ToLowerInvariant()) {
case AlignType.Center:
dX = 0.5 * te.Width;
break;
case AlignType.Right:
dX = te.Width;
break;
case AlignType.Left:
dX = 0;
break;
default:
return;
}
}
if (text.VAlign != null) {
switch (text.VAlign.ToLowerInvariant ()) {
case VAlignType.Top:
dY = te.YBearing;
break;
case VAlignType.Center:
dY = 0.5 * te.YBearing;
break;
case VAlignType.Bottom:
dY = 0;
break;
default:
return;
}
}
grw.MoveTo (
text.Start.GeometryX - dX,
text.Start.GeometryY - dY);
grw.ShowText (text.FormattedText);
grw.Stroke ();
}
示例14: DrawBoard
private void DrawBoard(Context cr, Position pos)
{
Console.WriteLine("ShogibanSVG.DrawBoard");
#region board border
//Top
cr.Rectangle(0, 0, Game.BOARD_SIZE * FIELD_SIZE + 2*FIELD_NAMING_SIZE, FIELD_NAMING_SIZE);
//Left
cr.Rectangle(0, 0, FIELD_NAMING_SIZE, Game.BOARD_SIZE * FIELD_SIZE + 2*FIELD_NAMING_SIZE);
//Bottom
cr.Rectangle(0, Game.BOARD_SIZE * FIELD_SIZE + FIELD_NAMING_SIZE, Game.BOARD_SIZE * FIELD_SIZE + 2*FIELD_NAMING_SIZE, FIELD_NAMING_SIZE);
//Right
cr.Rectangle(9*FIELD_SIZE + FIELD_NAMING_SIZE, 0, FIELD_NAMING_SIZE, Game.BOARD_SIZE * FIELD_SIZE + 2*FIELD_NAMING_SIZE);
cr.Color = BorderColor;
cr.Fill();
#endregion
#region field namings
cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);
cr.SetFontSize(FIELD_NAMING_SIZE * 0.9);
cr.Color = new Color(0, 0, 0);
for (int i = 0; i < VerticalNamings.Length; i++)
{
TextExtents extents = cr.TextExtents(VerticalNamings[i].ToString());
double x = (FIELD_NAMING_SIZE/2) - (extents.Width/2 + extents.XBearing);
double y = (FIELD_NAMING_SIZE + i*FIELD_SIZE + FIELD_SIZE/2) - (extents.Height/2 + extents.YBearing);
cr.MoveTo(x, y);
cr.ShowText(VerticalNamings[i].ToString());
cr.MoveTo(x + 9*FIELD_SIZE + FIELD_NAMING_SIZE, y);
cr.ShowText(VerticalNamings[i].ToString());
}
for (int i = 0; i < HorizontalNamings.Length; i++)
{
TextExtents extents = cr.TextExtents(HorizontalNamings[i].ToString());
double x = (FIELD_NAMING_SIZE + i*FIELD_SIZE + FIELD_SIZE/2) - (extents.Width/2 + extents.XBearing);
double y = (FIELD_NAMING_SIZE/2) - (extents.Height/2 + extents.YBearing);
cr.MoveTo(x, y);
cr.ShowText(HorizontalNamings[Game.BOARD_SIZE-i-1].ToString());
cr.MoveTo(x, y + 9*FIELD_SIZE + FIELD_NAMING_SIZE);
cr.ShowText(HorizontalNamings[Game.BOARD_SIZE-i-1].ToString());
}
#endregion
#region board playfield
//background
cr.Translate(FIELD_NAMING_SIZE, FIELD_NAMING_SIZE);
cr.Rectangle(0, 0, Game.BOARD_SIZE * FIELD_SIZE, Game.BOARD_SIZE * FIELD_SIZE);
cr.Color = BoardColor;
cr.Fill();
if (gi != null)
{
//highlight selected piece field
if (gi.localPlayerMoveState != LocalPlayerMoveState.Wait
&& gi.localPlayerMoveState != LocalPlayerMoveState.PickSource
&& CurMoveNr < 0)
{
if (gi.GetLocalPlayerMove().OnHandPiece == PieceType.NONE)
{
cr.Rectangle((Game.BOARD_SIZE - gi.GetLocalPlayerMove().From.x - 1) * FIELD_SIZE, gi.GetLocalPlayerMove().From.y * FIELD_SIZE, FIELD_SIZE, FIELD_SIZE);
cr.Color = SelectedFieldColor;
cr.Fill();
}
}
//highlight last move
if (gi.Moves.Count > 0 && CurMoveNr != 0)
{
Move move;
if (CurMoveNr < 0)
move = gi.Moves[gi.Moves.Count-1].move;
else
move = gi.Moves[CurMoveNr - 1].move;
if (move.OnHandPiece == PieceType.NONE)
{
cr.Rectangle((Game.BOARD_SIZE - move.From.x - 1) * FIELD_SIZE, move.From.y * FIELD_SIZE, FIELD_SIZE, FIELD_SIZE);
}
cr.Rectangle((Game.BOARD_SIZE - move.To.x - 1) * FIELD_SIZE, move.To.y * FIELD_SIZE, FIELD_SIZE, FIELD_SIZE);
cr.Color = LastMoveFieldColor;
cr.Fill();
}
//highlight possible moves
if (gi.localPlayerMoveState == LocalPlayerMoveState.PickDestination && CurMoveNr < 0)
{
ValidMoves Moves;
Move LocalPlayerMove = gi.GetLocalPlayerMove();
if (LocalPlayerMove.OnHandPiece == PieceType.NONE)
{
Moves = pos.GetValidBoardMoves(LocalPlayerMove.From);
}
else
{
Moves = pos.GetValidOnHandMoves(LocalPlayerMove.OnHandPiece, gi.CurPlayer == gi.BlackPlayer);
}
foreach (BoardField Field in Moves)
//.........这里部分代码省略.........
示例15: onDraw
protected override void onDraw(Context gr)
{
base.onDraw (gr);
gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
gr.SetFontSize (Font.Size);
gr.FontOptions = Interface.FontRenderingOptions;
gr.Antialias = Interface.Antialias;
rText = new Rectangle (new Size (
measureRawSize (LayoutingType.Width), measureRawSize (LayoutingType.Height)));
rText.Width -= 2 * Margin;
rText.Height -= 2 * Margin;
widthRatio = 1f;
heightRatio = 1f;
Rectangle cb = ClientRectangle;
//ignore text alignment if size to content = true
//or if text size is larger than client bounds
if (Width < 0 || Height < 0 || rText.Width > cb.Width) {
rText.X = cb.X;
rText.Y = cb.Y;
} else {
if (horizontalStretch) {
widthRatio = (float)cb.Width / rText.Width;
if (!verticalStretch)
heightRatio = widthRatio;
}
if (verticalStretch) {
heightRatio = (float)cb.Height / rText.Height;
if (!horizontalStretch)
widthRatio = heightRatio;
}
rText.Width = (int)(widthRatio * cb.Width);
rText.Height = (int)(heightRatio * cb.Height);
switch (TextAlignment) {
case Alignment.TopLeft: //ok
rText.X = cb.X;
rText.Y = cb.Y;
break;
case Alignment.Top: //ok
rText.Y = cb.Y;
rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
break;
case Alignment.TopRight: //ok
rText.Y = cb.Y;
rText.X = cb.Right - rText.Width;
break;
case Alignment.Left://ok
rText.X = cb.X;
rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
break;
case Alignment.Right://ok
rText.X = cb.X + cb.Width - rText.Width;
rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
break;
case Alignment.Bottom://ok
rText.X = cb.Width / 2 - rText.Width / 2;
rText.Y = cb.Height - rText.Height;
break;
case Alignment.BottomLeft://ok
rText.X = cb.X;
rText.Y = cb.Bottom - rText.Height;
break;
case Alignment.BottomRight://ok
rText.Y = cb.Bottom - rText.Height;
rText.X = cb.Right - rText.Width;
break;
case Alignment.Center://ok
rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
break;
}
}
gr.FontMatrix = new Matrix (widthRatio * Font.Size, 0, 0, heightRatio * Font.Size, 0, 0);
int curLineCount = 0;
for (int i = 0; i < lines.Count; i++) {
string l = lines [i].Replace ("\t", new String (' ', Interface.TabSize));
List<string> wl = new List<string> ();
int lineLength = (int)gr.TextExtents (l).XAdvance;
if (wordWrap && lineLength > cb.Width) {
string tmpLine = "";
int curChar = 0;
while (curChar < l.Length) {
tmpLine += l [curChar];
if ((int)gr.TextExtents (tmpLine).XAdvance > cb.Width) {
tmpLine = tmpLine.Remove (tmpLine.Length - 1);
wl.Add (tmpLine);
tmpLine = "";
continue;
}
curChar++;
}
//.........这里部分代码省略.........