本文整理汇总了C#中Xwt.Drawing.TextLayout类的典型用法代码示例。如果您正苦于以下问题:C# TextLayout类的具体用法?C# TextLayout怎么用?C# TextLayout使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextLayout类属于Xwt.Drawing命名空间,在下文中一共展示了TextLayout类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDraw
protected override void OnDraw(Context ctx, Rectangle dirtyRect)
{
// Line arround
ctx.SetColor(Colors.DarkGray);
// Drive line arround
ctx.Rectangle(Bounds);
ctx.Fill();
ctx.SetColor(Colors.Gray);
ctx.Rectangle(Bounds.Inflate(-margin, -margin));
ctx.Fill();
// Draw image
ctx.DrawImage(Image.FromResource(Logo), 5.0, 5.0);
// Draw text
ctx.SetColor(Colors.White);
TextLayout _layout = new TextLayout();
_layout.Font = Font.WithSize(22);
_layout.Text = Label;
_layout.SetFontWeight(FontWeight.Bold, 0, Label.Length);
// Cocoa layouts
ctx.DrawTextLayout(_layout, 45, ((Config.Cocoa || Config.Gtk) ? 5 : 2));
}
示例2: RenderLine
protected override LayoutWrapper RenderLine (long line)
{
var layout = new TextLayout (Editor);
layout.Font = Editor.Options.Font;
layout.Text = string.Format ("{0:X}", line * Editor.BytesInRow);
return new LayoutWrapper (layout);
}
示例3: RenderLine
protected override LayoutWrapper RenderLine (long line)
{
var layout = new TextLayout (Editor);
layout.Font = Editor.Options.Font;
StringBuilder sb = new StringBuilder ();
long startOffset = line * Editor.BytesInRow;
long endOffset = System.Math.Min (startOffset + Editor.BytesInRow, Data.Length);
byte[] lineBytes = Data.GetBytes (startOffset, (int)(endOffset - startOffset));
for (int i = 0; i < lineBytes.Length; i++) {
byte b = lineBytes[i];
char ch = (char)b;
if (b < 128 && (Char.IsLetterOrDigit (ch) || Char.IsPunctuation (ch))) {
sb.Append (ch);
} else {
sb.Append (".");
}
}
layout.Text = sb.ToString ();
Margin.LayoutWrapper result = new LayoutWrapper (layout);
if (Data.IsSomethingSelected) {
ISegment selection = Data.MainSelection.Segment;
HandleSelection (selection.Offset, selection.EndOffset, startOffset, endOffset, null, delegate(long start, long end) {
result.Layout.SetForeground (Style.Selection, (int)(start - startOffset), (int)(end - start));
result.Layout.SetBackground (Style.SelectionBg, (int)(start - startOffset), (int)(end - start));
});
}
return result;
}
示例4: OptionsChanged
internal protected override void OptionsChanged ()
{
var layout = new TextLayout (Editor);
layout.Font = Editor.Options.Font;
layout.Text = ".";
// int height;
charWidth = layout.GetSize ().Width;
layout.Dispose ();
}
示例5: OptionsChanged
internal protected override void OptionsChanged ()
{
var layout = new TextLayout (Editor);
layout.Font = Editor.Options.Font;
layout.Text = string.Format ("0{0:X}", Data.Length) + "_";
// int height;
width = layout.GetSize ().Width;
layout.Dispose ();
}
示例6: Draw
protected internal override void Draw(Context cr, Xwt.Rectangle area, DocumentLine line, int lineNumber, double x, double y, double height)
{
if (line != null)
{
TextLayout layout;
if (!layoutDict.TryGetValue(line, out layout))
{
var mode = editor.Document.SyntaxMode;
var style = SyntaxModeService.DefaultColorStyle;
var chunks = GetCachedChunks(mode, editor.Document, style, line, line.Offset, line.Length);
layout = new TextLayout();
layout.Font = editor.Options.EditorFont;
string lineText = editor.Document.GetLineText(lineNumber);
var stringBuilder = new StringBuilder(lineText.Length);
int currentVisualColumn = 1;
for (int i = 0; i < lineText.Length; ++i)
{
char chr = lineText[i];
if (chr == '\t')
{
int length = GetNextTabstop(editor, currentVisualColumn) - currentVisualColumn;
stringBuilder.Append(' ', length);
currentVisualColumn += length;
}
else
{
stringBuilder.Append(chr);
if (!char.IsLowSurrogate(chr))
{
++currentVisualColumn;
}
}
}
layout.Text = stringBuilder.ToString();
int visualOffset = 1;
foreach (var chunk in chunks)
{
var chunkStyle = style.GetChunkStyle(chunk);
visualOffset = DrawLinePortion(cr, chunkStyle, layout, line, visualOffset, chunk.Length);
}
//layoutDict[line] = layout;
}
cr.DrawTextLayout(layout, x, y);
if (editor.CaretVisible && editor.Caret.Line == lineNumber)
{
cr.SetColor(Colors.Black);
cr.Rectangle(x + ColumnToX(line, editor.Caret.Column), y, caretWidth, LineHeight);
cr.Fill();
}
}
}
示例7: LogLevelChooser
public LogLevelChooser(LogLevel selectedLogLevel)
{
SelectedLogLevel = selectedLogLevel;
// prerender
string[] logNames = Enum.GetNames(typeof(LogLevel));
int length = logNames.Length;
renderedImage = new Image[length];
using (TextLayout text = new TextLayout()) {
for (int i = 0; i < length; i++) {
text.Text = logNames[i];
Size size = text.GetSize();
using (ImageBuilder ib = new ImageBuilder(size.Width + size.Height*2 + 3, size.Height)) {
Color color = Color.FromName(Log.LevelToColorString((LogLevel) i));
Draw(ib.Context, (LogLevel) i, color);
renderedImage[i] = ib.ToBitmap();
Button button = new Button { Image = renderedImage[i], ImagePosition = ContentPosition.Left };
button.HorizontalPlacement = WidgetPlacement.Start;
button.Margin = 0;
button.ExpandHorizontal = true;
button.Style = ButtonStyle.Flat;
buttons.PackStart(button, true, true);
button.CanGetFocus = false;
button.Tag = i;
button.Clicked += OnLogChange;
windowHeight += size.Height * 2;
}
}
}
// hide window on lost fokus
buttons.CanGetFocus = true;
buttons.LostFocus += delegate {
if (menuHide != null) {
menuHide(this, EventArgs.Empty);
}
popupWindow.Hide();
};
buttons.ButtonPressed += delegate {
// do nothing
// workaround to propagate event to each button
};
buttons.Spacing = 0;
popupWindow.Padding = 0;
popupWindow.ShowInTaskbar = false;
popupWindow.Decorated = false;
popupWindow.Content = buttons;
}
示例8: OptionsChanged
internal protected override void OptionsChanged ()
{
var layout = new TextLayout (Editor);
layout.Font = Editor.Options.Font;
layout.Text = "!";
// int tmp;
this.marginWidth = layout.GetSize ().Height;
marginWidth *= 12;
marginWidth /= 10;
layout.Dispose ();
}
示例9: OnDraw
protected override void OnDraw (Context ctx, Rectangle cellArea)
{
PackageViewModel packageViewModel = GetValue (PackageField);
if (packageViewModel == null) {
return;
}
FillCellBackground (ctx);
UpdateTextColor (ctx);
DrawCheckBox (ctx, packageViewModel, cellArea);
DrawPackageImage (ctx, cellArea);
double packageIdWidth = cellArea.Width - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset;
// Package download count.
if (packageViewModel.HasDownloadCount) {
var downloadCountTextLayout = new TextLayout ();
downloadCountTextLayout.Text = packageViewModel.GetDownloadCountOrVersionDisplayText ();
Size size = downloadCountTextLayout.GetSize ();
Point location = new Point (cellArea.Right - packageDescriptionPadding.Right, cellArea.Top + packageDescriptionPadding.Top);
Point downloadLocation = location.Offset (-size.Width, 0);
ctx.DrawTextLayout (downloadCountTextLayout, downloadLocation);
packageIdWidth = downloadLocation.X - cellArea.Left - packageIdRightHandPaddingWidth - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset;
}
// Package Id.
var packageIdTextLayout = new TextLayout ();
packageIdTextLayout.Font = packageIdTextLayout.Font.WithSize (12);
packageIdTextLayout.Markup = packageViewModel.GetNameMarkup ();
packageIdTextLayout.Trimming = TextTrimming.WordElipsis;
Size packageIdTextSize = packageIdTextLayout.GetSize ();
packageIdTextLayout.Width = packageIdWidth;
ctx.DrawTextLayout (
packageIdTextLayout,
cellArea.Left + packageDescriptionPadding.Left + packageDescriptionLeftOffset,
cellArea.Top + packageDescriptionPadding.Top);
// Package description.
var descriptionTextLayout = new TextLayout ();
descriptionTextLayout.Font = descriptionTextLayout.Font.WithSize (11);
descriptionTextLayout.Width = cellArea.Width - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset;
descriptionTextLayout.Height = cellArea.Height - packageIdTextSize.Height - packageDescriptionPadding.VerticalSpacing;
descriptionTextLayout.Text = packageViewModel.Summary;
descriptionTextLayout.Trimming = TextTrimming.Word;
ctx.DrawTextLayout (
descriptionTextLayout,
cellArea.Left + packageDescriptionPadding.Left + packageDescriptionLeftOffset,
cellArea.Top + packageIdTextSize.Height + packageDescriptionPaddingHeight + packageDescriptionPadding.Top);
}
示例10: OnDraw
protected override void OnDraw (Context ctx, Rectangle dirtyRect)
{
base.OnDraw (ctx, dirtyRect);
ctx.Rectangle (0, 0, Size.Width, Size.Height);
ctx.SetColor (Colors.LightGray);
ctx.Fill ();
ctx.SetColor (Colors.Black);
using (var layout = new TextLayout (this))
{
layout.Text = text;
ctx.DrawTextLayout (layout, new Point (0, 20));
}
}
示例11: RenderLine
protected override LayoutWrapper RenderLine (long line)
{
var layout = new TextLayout (Editor);
layout.Font = Editor.Options.Font;
StringBuilder sb = new StringBuilder ();
long startOffset = line * Editor.BytesInRow;
long endOffset = System.Math.Min (startOffset + Editor.BytesInRow, Data.Length);
byte[] lineBytes = Data.GetBytes (startOffset, (int)(endOffset - startOffset));
switch (Editor.Options.StringRepresentationType) {
case StringRepresentationTypes.ASCII:
for (int i = 0; i < lineBytes.Length; i++) {
byte b = lineBytes [i];
char ch = (char)b;
if (!char.IsControl (ch)) {
sb.Append (ch);
} else {
sb.Append (".");
}
}
break;
case StringRepresentationTypes.UTF16:
for (int i = 0; i < lineBytes.Length - 1; i += 2) {
char ch = Encoding.Unicode.GetChars (lineBytes, i, 2) [0];
if (char.IsLetterOrDigit (ch) || char.IsWhiteSpace (ch) || char.IsSymbol (ch) || char.IsPunctuation (ch))
sb.Append (ch);
else
sb.Append (".");
}
break;
default:
throw new NotImplementedException (Editor.Options.StringRepresentationType.ToString ());
}
layout.Text = sb.ToString ();
Margin.LayoutWrapper result = new LayoutWrapper (layout);
if (Data.IsSomethingSelected) {
ISegment selection = Data.MainSelection.Segment;
HandleSelection (selection.Offset, selection.EndOffset, startOffset, endOffset, null, delegate(long start, long end) {
result.Layout.SetForeground (Style.Selection, (int)(start - startOffset)/2, (int)(end - start)/2);
result.Layout.SetBackground (Style.SelectionBg, (int)(start - startOffset)/2, (int)(end - start)/2);
});
}
return result;
}
示例12: Draw
protected internal override void Draw(Context cr, Xwt.Rectangle area, DocumentLine line, int lineNumber, double x, double y, double height)
{
if (lineNumber <= editor.Document.LineCount)
{
TextLayout layout;
if (!layoutDict.TryGetValue(lineNumber, out layout))
{
layout = new TextLayout();
layout.Font = editor.Options.EditorFont;
layout.Text = lineNumber.ToString();
layoutDict[lineNumber] = layout;
}
cr.SetColor(Colors.Black);
cr.DrawTextLayout(layout, x + leftPadding, y);
}
}
示例13: DrawLinePortion
int DrawLinePortion(Context cr, ChunkStyle style, TextLayout layout, DocumentLine line, int visualOffset, int logicalLength)
{
int logicalColumn = line.GetLogicalColumn(editor, visualOffset);
int logicalEndColumn = logicalColumn + logicalLength;
int visualEndOffset = line.GetVisualColumn(editor, logicalEndColumn);
int visualLength = visualEndOffset - visualOffset;
int indexOffset = visualOffset - 1;
layout.SetFontStyle(style.FontStyle, indexOffset, visualLength);
layout.SetFontWeight(style.FontWeight, indexOffset, visualLength);
if (style.Underline)
layout.SetUnderline(indexOffset, visualLength);
layout.SetForeground(style.Foreground, indexOffset, visualLength);
return visualEndOffset;
}
示例14: OnDraw
protected override void OnDraw(Context ctx, Rectangle dirtyRect)
{
base.OnDraw(ctx, dirtyRect);
ctx.SetColor(Colors.Gray);
ctx.SetLineWidth(1);
ctx.RoundRectangle(0, Padding.Top / 2 - .5, Width - 4.5, Height - Padding.Bottom * 1.5, 3);
ctx.Stroke();
var tl = new TextLayout(this) { Text = title, Width = Width - Padding.Left - Padding.Right / 2 };
ctx.SetColor(Colors.White);
ctx.Rectangle(Padding.Left, 0, tl.GetSize().Width, Padding.Top);
ctx.Fill();
ctx.SetColor(Colors.Black);
ctx.DrawTextLayout(tl, Padding.Left, 0);
}
示例15: OptionsChanged
internal protected override void OptionsChanged ()
{
var layout = new TextLayout (Editor);
layout.Font = Editor.Options.Font;
string groupString = new string ('0', Editor.Options.GroupBytes * 2);
layout.Text = groupString + " ";
double lineHeight;
var sz = layout.GetSize ();
groupWidth = sz.Width;
lineHeight = sz.Height;
Data.LineHeight = lineHeight;
layout.Text = "00";
byteWidth = layout.GetSize ().Width;
layout.Dispose ();
// tabArray = new Pango.TabArray (1, true);
// tabArray.SetTab (0, Pango.TabAlign.Left, groupWidth);
}