本文整理汇总了C#中Cairo.Context.TextExtents方法的典型用法代码示例。如果您正苦于以下问题:C# Context.TextExtents方法的具体用法?C# Context.TextExtents怎么用?C# Context.TextExtents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cairo.Context
的用法示例。
在下文中一共展示了Context.TextExtents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PaintEdges
private void PaintEdges(Context ctx, int w, int h, IEnumerable<NotatedEdge> edges)
{
PointD pc, pd;
foreach(NotatedEdge edge in edges) {
PointD pa = new PointD(w*edge.Item1.X, h*edge.Item1.Y);
PointD pb = new PointD(w*edge.Item2.X, h*edge.Item2.Y);
Utils.CutTowardsCenter(pa, pb, AlgorithmRadius, out pc, out pd);
double dxr = pc.X-pd.X;
double dyr = pc.Y-pd.Y;
double r = Math.Sqrt(dxr*dxr+dyr*dyr);
ctx.MoveTo(pc);
ctx.LineTo(pd);
ctx.Stroke();
ctx.Save();
ctx.Translate(pc.X, pc.Y);
ctx.Rotate(Math.Atan2(pb.Y-pa.Y, pb.X-pa.X));
double v = 0.0d;//double v = tm/e.Delay;
foreach(EdgeNotation msg in edge.Item3) {
TextExtents te = ctx.TextExtents(msg.Item2);
ctx.MoveTo((msg.Item1+v)*(r-te.XAdvance), te.Height+2.0d);
ctx.ShowText(msg.Item2);
}
ctx.Restore();
ctx.Save();
ctx.Translate(pd.X, pd.Y);
ctx.Rotate(Math.Atan2(pa.Y-pb.Y, pa.X-pb.X));
foreach(EdgeNotation msg in edge.Item4) {
TextExtents te = ctx.TextExtents(msg.Item2);
ctx.MoveTo((msg.Item1+v)*(r-te.XAdvance), te.Height+2.0d);
ctx.ShowText(msg.Item2);
}
ctx.Restore();
}
}
示例2: DrawRightsideHorisontalNumbers
protected void DrawRightsideHorisontalNumbers(Context g, Gdk.Rectangle area, float ySize)
{
for (int i = 0; i <= NumbersY; i++) {
float actualLoc = (1 - i/NumbersY) * (area.Height - numberSpacingYTotal) + NumberSpacingYUp;
String text = (i*ySize/NumbersY).ToString ("0.0");
TextExtents size = g.TextExtents (text);
g.MoveTo (area.Width-NumberSpacingXRight, actualLoc + size.Height / 2);
g.ShowText (text);
}
}
示例3: Text
public void Text(Context context, string txt, HorizontalTextAlignment horizontal = HorizontalTextAlignment.Center, VerticalTextAlignment vertical = VerticalTextAlignment.Middle)
{
context.SelectFontFace ("Sans", FontSlant.Normal, FontWeight.Normal);
//context.SetFontSize (_surface.Height / 10);
context.SetFontSize (14);
var extends = context.TextExtents (txt);
double x, y;
x = -(((double)horizontal) / 2 * extends.Width + extends.XBearing);
y = -(((double)vertical) / 2 * extends.Height + extends.YBearing);
context.RelMoveTo (x, y);
context.ShowText (txt);
}
示例4: GetXFromTextPointer
/// <summary> Compute x offset in cairo unit from text position </summary>
double GetXFromTextPointer(Context gr, Point pos)
{
try {
string l = lines [pos.Y].Substring (0, pos.X).
Replace ("\t", new String (' ', Interface.TabSize));
return gr.TextExtents (l).XAdvance;
} catch{
return -1;
}
}
示例5: Paint
public virtual void Paint(Context ctx)
{
PointD size = this.MeasureSize (ctx);
PaintContour (ctx,size);
KnownColors.SetFontFacePieceName(ctx);
TextExtents te = ctx.TextExtents(this.Name), ten;
double y0 = 0.5d*(size.Y-te.Width);
ctx.MoveTo(0.5d*Margin,y0);
ctx.Save();
ctx.Rotate(0.5d*Math.PI);
ctx.ShowText(this.Name);
ctx.Restore();
double x0 = Margin+te.Height;
KnownColors.SetFontFaceNormal(ctx);
te = ctx.TextExtents(OptionalString);
y0 = 2.0d*Margin;
int index = 0x00;
PointD siz;
foreach(IPuzzlePiece ipp in this.arguments) {
ctx.Save();
ctx.Translate(x0,Margin);
if(ipp == null) {
siz = new PointD(MinimumWidth,size.Y-4.0d*Margin);
ctx.Rectangle(Margin,Margin,siz.X,siz.Y);
ctx.Pattern = KnownColors.ConstructionPattern;
ctx.FillPreserve();
}
else {
siz = ipp.MeasureSize(ctx);
}
ctx.Rectangle(0.0d,0.0d,siz.X+2.0d*Margin,siz.Y+2.0d*Margin);
ctx.Color = KnownColors.Black;
ctx.StrokePreserve();
if(ipp == null) {
ctx.Pattern = ExtensionMethods.GenerateColorSequencePattern(siz.X+2.0d*Margin,TypeColorArguments[index]);
ctx.Fill();
ctx.Translate(Margin,Margin);
ctx.MoveTo(0.0d,0.0d);
ctx.LineTo(MinimumWidth,0.0d);
ctx.RelLineTo(0.0d,5.0d);
ctx.LineTo(5.0d,5.0d);
ctx.ClosePath();
ctx.Pattern = KnownColors.ShadowDownPattern;
ctx.Fill();
ctx.MoveTo(0.0d,0.0d);
ctx.LineTo(0.0d,siz.Y);
ctx.RelLineTo(5.0d,0.0d);
ctx.LineTo(5.0d,5.0d);
ctx.ClosePath();
ctx.Pattern = KnownColors.ShadowRightPattern;
ctx.Fill();
}
else {
ctx.Pattern = ExtensionMethods.GenerateColorSequencePattern(siz.X+2.0d*Margin,TypeColorArguments[index]);
ctx.Fill();
ctx.Color = KnownColors.Black;
ctx.Translate(Margin,Margin);
ipp.Paint(ctx);
}
ctx.Restore();
subpieces[index] = new Rectangle(x0+Margin,2.0d*Margin,siz.X,siz.Y);
x0 += siz.X+3.0d*Margin;
if(index >= NumberOfArguments-NumberOfOptionalArguments) {
ctx.MoveTo(x0-2.0d*Margin-0.5d*(siz.X+te.Width),siz.Y+3.0d*Margin-2.0d);
ctx.ShowText(OptionalString);
}
if(this.ArgumentNames != null && index < arguments.Length) {
ten = ctx.TextExtents(this.ArgumentNames[index]);
ctx.MoveTo(x0-2.0d*Margin-0.5d*(siz.X+ten.Width),-te.YBearing+Margin+2.0d);
ctx.ShowText(this.ArgumentNames[index]);
}
index++;
}
}
示例6: 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();
}
示例7: onDraw
//.........这里部分代码省略.........
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;
}
}
}else
computeTextCursorPosition(gr);
Foreground.SetAsSource (gr);
gr.LineWidth = 1.0;
gr.MoveTo (0.5 + textCursorPos + rText.X, rText.Y + CurrentLine * fe.Height);
gr.LineTo (0.5 + textCursorPos + rText.X, rText.Y + (CurrentLine + 1) * fe.Height);
gr.Stroke();
}
#endregion
//****** debug selection *************
// if (SelRelease >= 0) {
// gr.Color = Color.Green;
// Rectangle R = new Rectangle (
// rText.X + (int)SelEndCursorPos - 2,
// rText.Y + (int)(SelRelease.Y * fe.Height),
// 4,
// (int)fe.Height);
// gr.Rectangle (R);
// gr.Fill ();
// }
// if (SelBegin >= 0) {
// gr.Color = Color.UnmellowYellow;
// Rectangle R = new Rectangle (
// rText.X + (int)SelStartCursorPos - 2,
// rText.Y + (int)(SelBegin.Y * fe.Height),
// 4,
// (int)fe.Height);
// gr.Rectangle (R);
// gr.Fill ();
// }
//*******************
for (int i = 0; i < lines.Count; i++) {
string l = lines [i].Replace ("\t", new String (' ', Interface.TabSize));
int lineLength = (int)gr.TextExtents (l).XAdvance;
Rectangle lineRect = new Rectangle (
rText.X,
rText.Y + (int)Math.Ceiling(i * fe.Height),
lineLength,
(int)Math.Ceiling(fe.Height));
// if (TextAlignment == Alignment.Center ||
// TextAlignment == Alignment.Top ||
// TextAlignment == Alignment.Bottom)
// lineRect.X += (rText.Width - lineLength) / 2;
// else if (TextAlignment == Alignment.Right ||
// TextAlignment == Alignment.TopRight ||
// TextAlignment == Alignment.BottomRight)
// lineRect.X += (rText.Width - lineLength);
if (Selectable) {
if (SelRelease >= 0 && i >= selectionStart.Y && i <= selectionEnd.Y) {
gr.SetSourceColor (selBackground);
Rectangle selRect = lineRect;
int cpStart = (int)SelStartCursorPos,
cpEnd = (int)SelEndCursorPos;
if (SelBegin.Y > SelRelease.Y) {
cpStart = cpEnd;
cpEnd = (int)SelStartCursorPos;
}
if (i == selectionStart.Y) {
selRect.Width -= cpStart;
selRect.Left += cpStart;
}
if (i == selectionEnd.Y)
selRect.Width -= (lineLength - cpEnd);
gr.Rectangle (selRect);
gr.Fill ();
}
}
if (string.IsNullOrWhiteSpace (l))
continue;
Foreground.SetAsSource (gr);
gr.MoveTo (lineRect.X, rText.Y + fe.Ascent + fe.Height * i);
gr.ShowText (l);
gr.Fill ();
}
}
示例8: DrawOnHandPieces
private void DrawOnHandPieces(Context cr, Position pos, bool BlackPlayer)
{
cr.Save();
cr.Rectangle(0, 0, ON_HAND_AREA_WIDTH, 9 * FIELD_SIZE + 2 * FIELD_NAMING_SIZE);
cr.Color = BorderColor;
cr.FillPreserve();
cr.Color = new Color(0.6, 0.5, 0.55);
cr.LineWidth = 3;
cr.Stroke();
if (BlackPlayer)
{
cr.Translate(0, 8 * FIELD_SIZE + 2 * FIELD_NAMING_SIZE);
}
for (int i = 0; i < (int)PieceType.PIECE_TYPES_COUNT; i++)
{
int player_nr = BlackPlayer ? 0 : 1;
if (pos.OnHandPieces[player_nr, i] != 0)
{
//highlight selected piece
if (gi != null && gi.localPlayerMoveState != LocalPlayerMoveState.Wait
&& gi.localPlayerMoveState != LocalPlayerMoveState.PickSource
&& gi.GetLocalPlayerMove().OnHandPiece != PieceType.NONE
&& gi.GetLocalPlayerMove().OnHandPiece == (PieceType)i
&& !((gi.CurPlayer == gi.BlackPlayer) ^ BlackPlayer))
{
cr.Rectangle(0, 0, FIELD_SIZE, FIELD_SIZE);
cr.Color = new Color(0.8, 0.835, 0.4);
cr.Fill();
}
//draw piece
cr.Save();
if (!BlackPlayer)
{
cr.Rotate(180 * Math.PI / 180);
cr.Translate(-FIELD_SIZE, -FIELD_SIZE);
}
cr.Scale(FIELD_SIZE / PieceGraphics[i].Dimensions.Width, FIELD_SIZE / PieceGraphics[i].Dimensions.Width);
PieceGraphics[i].RenderCairo(cr);
cr.Restore();
//draw amount
cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);
cr.SetFontSize(FIELD_SIZE / 3 * 0.9);
cr.Color = new Color(0, 0, 0);
String amount_str = "x " + pos.OnHandPieces[player_nr, i].ToString();
TextExtents extents = cr.TextExtents(amount_str);
double x = (FIELD_SIZE);
// - (extents.Width/2 + extents.XBearing);
double y = (FIELD_SIZE / 2) - (extents.Height / 2 + extents.YBearing);
cr.MoveTo(x, y);
cr.ShowText(amount_str);
double offset = BlackPlayer ? -FIELD_SIZE - PADDING : FIELD_SIZE + PADDING;
cr.Translate(0, offset);
}
}
cr.Restore();
}
示例9: 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);
}
示例10: DrawWeatherRegion
private void DrawWeatherRegion(Context g, RegionDto dto)
{
string trendIcon = string.Empty;
g.SetSourceRGB(1, 1, 1);
double halfWidth = dto.Width / 2.0;
TextExtents extDay;
if (string.IsNullOrEmpty(dto.WeekDay))
{
extDay = g.TextExtents("test");
}
else
{
extDay = g.TextExtents(dto.WeekDay);
}
var t_x = dto.X + halfWidth - (extDay.Width / 2);
var t_y = dto.Y + extDay.Height + padding;
this.DrawTextAt(g, t_x, t_y, dto.WeekDay);
//drawe day temp
var extMax = g.TextExtents(dto.Max);
var extMin = g.TextExtents(dto.Min);
t_y = t_y + extDay.Height + padding + 2;
t_x = dto.X + halfWidth - (extMax.Width / 2);
this.DrawTextAt(g, t_x, t_y, dto.Max);
if (dto.Trend.HasValue)
{
if (dto.Trend.Value > 0)
{
trendIcon = "up.png";
}
else
if (dto.Trend < 0)
{
trendIcon = "dwn.png";
}
if (!string.IsNullOrEmpty(trendIcon))
{
string pathToImg = global::System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("Icons/{0}", trendIcon));
ImageSurface image_surface = new ImageSurface(pathToImg);
this.DrawSurfaceAt(g, image_surface, t_x - extMax.Width / 2, t_y - extMax.Height);
}
}
t_x = dto.X + halfWidth - imageWidth / 2;
DrawWeatherCode(g, dto.WeatherCode, t_x, t_y);
g.SetSourceRGB(0.7, 0.7, 0.7);
t_x = dto.X + halfWidth - (extMin.Width / 2);
t_y += 68 + extMax.Height / 2;
this.DrawTextAt(g, t_x, t_y, dto.Min);
}
示例11: 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)
//.........这里部分代码省略.........
示例12: RenderSkillCell
private void RenderSkillCell(Context context, Gdk.Rectangle pix_rect, bool isSelected)
{
int osOffset = 0;
int startX = pix_rect.Right - 64;
if(ECM.Helper.CurrentPlatform == ECM.Helper.Platform.Windows)
osOffset = 1;
// Render Text
context.Save();
Color col = White;
//if (!isSelected)
// col = Black;
string s = string.Format("{0} ({1}x)", Text, SkillRank);
TextExtents te = context.TextExtents(s);
RenderText(context, s, pix_rect.X + 32, pix_rect.Y + 2, col);
s = string.Format("Level {0}", SkillLevel);
te = context.TextExtents(s);
RenderText(context, s, startX - (te.Width + 6), pix_rect.Y + 2, col);
s = ECM.Helper.GetDurationInWordsShort(TimeSpan.FromMinutes(SkillMinsToNext));
te = context.TextExtents(s);
RenderText(context, s, startX - (te.Width + 6), pix_rect.Y + te.Height + 6, col);
s = string.Format("SP {0:0,0}/{1:0,0}", SkillCurrSP, SkillNextSP);
context.SelectFontFace(m_FontDesc.Family, FontSlant.Normal, FontWeight.Bold);
te = context.TextExtents(s);
RenderText(context, s, pix_rect.X + 32, pix_rect.Y + te.Height + 6, col);
context.Restore();
// Render Progress bars
context.Save();
context.Color = Gray;
context.Antialias = Antialias.None;
context.LineWidth = 1;
for (int i = 0; i < SkillLevel; i++)
{
context.Rectangle(startX + 2 + i * 9, pix_rect.Y + 3 + osOffset, 8, 6);
}
// Time Bar
double fullWidth = 44;
double dist = SkillNextSP - SkillLevlSP;
double trav = SkillCurrSP - SkillLevlSP;
double perc = 1;
if(dist > 0)
perc = Math.Max(0, trav / dist);
context.Rectangle(startX + 2, pix_rect.Y + 17 + osOffset, fullWidth * perc, 2);
context.Fill();
context.Rectangle(startX, pix_rect.Y + 2, 47, 9);
context.Rectangle(startX, pix_rect.Y + 16, 47, 5);
context.Stroke();
context.Restore();
// Render Skillbook Icon
context.Save();
Gdk.CairoHelper.SetSourcePixbuf(context, new Gdk.Pixbuf(ECM.Core.SkillbookPNG), pix_rect.X, pix_rect.Y);
context.Paint();
context.Restore();
}
示例13: 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;
//.........这里部分代码省略.........
示例14: DrawVerticalReferenceLines
protected void DrawVerticalReferenceLines(Context g, Gdk.Rectangle area, float xSize, float xTranslation)
{
for (int i = 0; i <= NumbersX; i++) {
float actualLoc = i * (area.Width - numberSpacingXTotal) / NumbersX + NumberSpacingXLeft;
String text = (xTranslation+i*xSize/NumbersX).ToString ("0.0");
g.MoveTo (actualLoc - g.TextExtents (text).Width / 2, area.Height - 5);
g.ShowText (text);
g.MoveTo (actualLoc, area.Height - NumberSpacingYDown);
g.LineTo (actualLoc, NumberSpacingYUp);
g.Stroke ();
}
}
示例15: paintNodes
private void paintNodes(Context ctx, int w, int h, IEnumerable<Node> nodes)
{
ctx.LineWidth = 2.0d;
foreach(Node node in nodes) {
PointD abs = new PointD(node.Item2.X*w, node.Item2.Y*h);
ctx.Arc(abs.X, abs.Y, AlgorithmRadius, 0.0d, 2.0d*Math.PI);
ctx.ClosePath();
ctx.NewSubPath();
ctx.Arc(abs.X, abs.Y, AlgorithmRadius-BlueprintStyle.Thickness, 0.0d, 2.0d*Math.PI);
ctx.ClosePath();
ctx.NewSubPath();
}
ctx.Pattern = BlueprintStyle.FillPattern;
ctx.FillPreserve();
ctx.Color = BlueprintStyle.HardWhite;
ctx.Stroke();
double r_2, dx, dy;
this.nodeCenters.Clear();
foreach(Node node in nodes) {
PointD abs = new PointD(node.Item2.X*w, node.Item2.Y*h);
this.nodeCenters.Add(abs);
TextExtents te = ctx.TextExtents(node.Item1);
r_2 = (AlgorithmRadius-BlueprintStyle.Thickness)/Math.Sqrt(te.Width*te.Width+te.Height*te.Height);
ctx.Save();
ctx.MoveTo(abs.X-r_2*te.Width, abs.Y+r_2*te.Height);
ctx.Scale(2.0d*r_2, 2.0d*r_2);
ctx.ShowText(node.Item1);
ctx.Restore();
}
}