public void Draw(RenderContext renderContext, float opacity, Color color) { if (renderContext.gl == null) { Vector3d viewPoint = Vector3d.TransformCoordinate(renderContext.ViewPoint, ViewTransform); double drawHeight = (Height / renderContext.FovAngle) * renderContext.Height / 180; foreach (Text3d t3d in Items) { Vector3d screenSpacePnt = renderContext.WVP.Transform(t3d.center); if (screenSpacePnt.Z < 0) { continue; } if (Vector3d.Dot((Vector3d)viewPoint, (Vector3d)t3d.center) < .55) { continue; } Vector3d screenSpaceTop = renderContext.WVP.Transform(t3d.top); double rotation = Math.Atan2(screenSpacePnt.X - screenSpaceTop.X, screenSpacePnt.Y - screenSpaceTop.Y); CanvasContext2D ctx = renderContext.Device; ctx.Save(); ctx.Translate(screenSpacePnt.X, screenSpacePnt.Y); ctx.Rotate(-rotation); // todo update with up vector ctx.Alpha = opacity; ctx.FillStyle = color.ToString(); ctx.Font = "normal" + " " + (false ? "bold" : "normal") + " " + Math.Round(drawHeight * 1.2).ToString() + "px " + "Arial"; ctx.TextBaseline = TextBaseline.Top; TextMetrics tm = ctx.MeasureText(t3d.Text); ctx.FillText(t3d.Text, -tm.Width / 2, -drawHeight / 2); ctx.Restore(); } } else { // gl version if (glyphCache == null || glyphCache.Version > glyphVersion) { PrepareBatch(); } if (glyphCache.Ready == false) { return; } TextShader.Use(renderContext, vertexBuffer.VertexBuffer, glyphCache.Texture.Texture2d); renderContext.gl.drawArrays(GL.TRIANGLES, 0, vertexBuffer.Count); } }
protected void RedrawBaseTextImage() { UpdateFont(); string[] lines = _Text.Split('\n'); float H = FontSize * 1f; int W = 0; int i = 0; while (i < lines.Length) { TextMetrics TM = TextGraphic.MeasureText(lines[i]); W = Math.Max(W, (int)Math.Ceiling(TM.Width)); i++; } //TextImage.Height = (int)(H * (lines.Length+0.5f)); TextImage.Height = (int)(H * (lines.Length + 0.25f)); TextImage.Width = W; UpdateFont(); float Y = 0; i = 0; while (i < lines.Length) { TextGraphic.FillText(lines[i], 0, (int)(FontSize + Y)); Y += H; i++; } textInvallidated = false; imageInvallidated = true; }
/// <summary> /// /// </summary> /// <param name="directWriteFactory"></param> /// <param name="caption"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="width"></param> /// <param name="height"></param> public Button(SharpDX.DirectWrite.Factory directWriteFactory, string caption, float x, float y, float width = BUTTON_STANDARD_WIDTH, float height = BUTTON_STANDARD_HEIGHT) { Caption = caption; X = x; Y = y; Width = width; Height = height; hovered = false; pressed = false; TextColor = SolidColorBrushes.White; roundedRectangle = new RoundedRectangle(); roundedRectangle.RadiusX = 8; roundedRectangle.RadiusY = 8; rect = new RectangleF(x, y, width, height); roundedRectangle.Rect = rect; textLayout = new TextLayout(directWriteFactory, caption, FormFonts.ButtonNormalFont, width, height); TextMetrics textMetrics = textLayout.Metrics; textPosition = new Vector2(x + ((width / 2f) - (textMetrics.Width / 2f)), y + ((height / 2f) - (textMetrics.Height / 2f))); }
private void DetermineMaxItemSize(IDrawingContext dc, Item[] items, out SizeInt32 maxItemSizeResult, out SizeInt32 maxImageSizeResult) { int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; foreach (Item item in items) { num = Math.Max(num, (item.Image == null) ? 0 : item.Image.Width); num2 = Math.Max(num2, (item.Image == null) ? 0 : item.Image.Height); TextLayoutAlgorithm?layoutAlgorithm = null; TextLayout resourceSource = UIText.CreateLayout(dc, item.Name, this.Font, layoutAlgorithm, HotkeyRenderMode.Ignore, 65535.0, 65535.0); TextMetrics metrics = dc.GetCachedOrCreateResource <ITextLayout>(resourceSource).Metrics; SizeInt32 num9 = new SizeInt32((int)Math.Ceiling((double)metrics.WidthMax), (int)Math.Ceiling((double)metrics.Height)); num3 = Math.Max(num9.Width, num3); num4 = Math.Max(num9.Height, num4); } int recommendedExtent = this.dropShadowRenderer.GetRecommendedExtent(num, num2); int width = ((((((recommendedExtent + this.imageXInset) + num) + this.imageXInset) + recommendedExtent) + this.textLeftMargin) + num3) + this.textRightMargin; int height = Math.Max((int)((((this.imageYInset + recommendedExtent) + num2) + this.imageYInset) + recommendedExtent), (int)((this.textVMargin + num4) + this.textVMargin)); maxItemSizeResult = new SizeInt32(width, height); maxImageSizeResult = new SizeInt32(num, num2); }
public TextInfo GetTextInfo(Graphics graphics, Font font) { TextMetrics metrics = visualStyleRenderer.GetTextMetrics(graphics); TextInfo info = new TextInfo(); info.Height = metrics.Height; return(info); }
public void SciterPoint_width_and_height_from_ctor(float minWidth, float maxWidth, float height, float ascent, float descent, int noLines) { var actual = new TextMetrics(minWidth, maxWidth, height, ascent, descent, noLines); Assert.AreEqual(ascent, actual.Ascent); Assert.AreEqual(descent, actual.Descent); Assert.AreEqual(height, actual.Height); Assert.AreEqual(noLines, actual.LineCount); Assert.AreEqual(maxWidth, actual.MaxWidth); Assert.AreEqual(minWidth, actual.MinWidth); }
public Column(SharpDX.DirectWrite.Factory directWriteFactory, string caption, string fieldName, float width, float height) { Caption = caption; FieldName = fieldName; Width = width; Height = height; TextLayout = new TextLayout(directWriteFactory, caption, FormFonts.ColumnHeaderFont, width, height); TextMetrics textMetrics = TextLayout.Metrics; TextLayout.ParagraphAlignment = ParagraphAlignment.Near; }
// Token: 0x0600019D RID: 413 RVA: 0x00014520 File Offset: 0x00012720 public Vector2 MeasureText(string text, float fontSize = 13f, string fontFamily = "Calibri") { TextFormat orCreate = this.textFormatCache.GetOrCreate(fontFamily, fontSize); Vector2 result; using (TextLayout textLayout = new TextLayout(this.context.DirectWrite, text, orCreate, float.MaxValue, float.MaxValue)) { TextMetrics metrics = textLayout.Metrics; result = new Vector2(metrics.Width, metrics.Height); } return(result); }
public static Point ApplyTextAlign(Point point, string align, string text, TextMetrics size) { switch (align) { case "left": return point; case "center": return new Point(point.X - size.width/2f, point.Y); case "right": return new Point(point.X - size.width, point.Y); } return point; }
public void TextMetrics_AverageCharWidth_Set_GetReturnsExpected(int value) { var metric = new TextMetrics { AverageCharWidth = value }; Assert.Equal(value, metric.AverageCharWidth); // Set same. metric.AverageCharWidth = value; Assert.Equal(value, metric.AverageCharWidth); }
public void TextMetrics_BreakChar_Set_GetReturnsExpected(char value) { var metric = new TextMetrics { BreakChar = value }; Assert.Equal(value, metric.BreakChar); // Set same. metric.BreakChar = value; Assert.Equal(value, metric.BreakChar); }
public void TextMetrics_CharSet_Set_GetReturnsExpected(TextMetricsCharacterSet value) { var metric = new TextMetrics { CharSet = value }; Assert.Equal(value, metric.CharSet); // Set same. metric.CharSet = value; Assert.Equal(value, metric.CharSet); }
public void TextMetrics_Ascent_Set_GetReturnsExpected(int value) { var metric = new TextMetrics { Ascent = value }; Assert.Equal(value, metric.Ascent); // Set same. metric.Ascent = value; Assert.Equal(value, metric.Ascent); }
public void TextMetrics_Underlined_Set_GetReturnsExpected(bool value) { var metric = new TextMetrics { Underlined = value }; Assert.Equal(value, metric.Underlined); // Set same. metric.Underlined = value; Assert.Equal(value, metric.Underlined); }
static void Main(string[] args) { var messages = new TextMessages(); var repo = new TextRepository(); var metrics = new TextMetrics(); Console.WriteLine("Listening for ExchangeTextRankCalculated event, press Ctrl+C to stop..."); messages.ConsumeMessagesInLoop(TextMessages.QueueTextSuccessMarker, TextMessages.ExchangeTextRankCalculated, (model, json) => { var message = TextRankCalculatedMessage.FromJson(json); bool isTextSuccessful = (message.Score > minSuccessfulScore); messages.SendTextSuccessMarked(message.ContextId, isTextSuccessful); }); }
public void TextMetrics_PitchAndFamily_GetReturnsExpected(TextMetricsPitchAndFamilyValues value) { var metric = new TextMetrics { PitchAndFamily = value }; Assert.Equal(value, metric.PitchAndFamily); // Set same. metric.PitchAndFamily = value; Assert.Equal(value, metric.PitchAndFamily); }
public void TextMetrics_StruckOut_Set_GetReturnsExpected(bool value) { var metric = new TextMetrics { StruckOut = value }; Assert.Equal(value, metric.StruckOut); // Set same. metric.StruckOut = value; Assert.Equal(value, metric.StruckOut); }
public void TextMetrics_Italic_Set_GetReturnsExpected(bool value) { var metric = new TextMetrics { Italic = value }; Assert.Equal(value, metric.Italic); // Set same. metric.Italic = value; Assert.Equal(value, metric.Italic); }
public void TextMetrics_Overhang_Set_GetReturnsExpected(int value) { var metric = new TextMetrics { Overhang = value }; Assert.Equal(value, metric.Overhang); // Set same. metric.Overhang = value; Assert.Equal(value, metric.Overhang); }
public void TextMetrics_InternalLeading_Set_GetReturnsExpected(int value) { var metric = new TextMetrics { InternalLeading = value }; Assert.Equal(value, metric.InternalLeading); // Set same. metric.InternalLeading = value; Assert.Equal(value, metric.InternalLeading); }
public void TextMetrics_DigitizedAspectY_Set_GetReturnsExpected(int value) { var metric = new TextMetrics { DigitizedAspectY = value }; Assert.Equal(value, metric.DigitizedAspectY); // Set same. metric.DigitizedAspectY = value; Assert.Equal(value, metric.DigitizedAspectY); }
static void Main(string[] args) { var messages = new TextMessages(); var repo = new TextRepository(); var metrics = new TextMetrics(); Console.WriteLine("Listening for ExchangeProcessingAccepted event, press Ctrl+C to stop..."); messages.ConsumeMessagesInLoop(TextMessages.QueueTextRancCalc, TextMessages.ExchangeProcessingAccepted, (model, json) => { var message = TextProcessingAcceptedMessage.FromJson(json); if (message.Accepted) { messages.SendTextRankTask(message.ContextId); } }); }
protected override void OnRender(WindowRenderTarget renderTarget) { float y = 0; for (int index = 0; index < this._paragraphs.Count; ++index) { using (TextFormat textFormat = DirectWriteFactory.CreateTextFormat( this._paragraphs[index].FontFamily, this._paragraphs[index].Weight, this._paragraphs[index].FontSize * 96f / 72f)) { textFormat.TextAlignment = _paragraphs[index].TextAlignment; LineSpacing lineSpacing = textFormat.LineSpacing; if (_paragraphs[index].LineSpacing == 0) { textFormat.LineSpacing = LineSpacing.Default; } else { textFormat.LineSpacing = new LineSpacing(_paragraphs[index].LineSpacing); } float width = ClientSize.Width / DpiScaleX - (_marginLeft + _marginRight); using (TextLayout textLayout = DirectWriteFactory.CreateTextLayout( this._paragraphs[index].Text, textFormat, width, 0)) { y += _paragraphs[index].SpaceBefore; renderTarget.DrawTextLayout( new PointF(_marginLeft, y), textLayout, _blackBrush, DrawTextOptions.None); TextMetrics metrics = textLayout.Metrics; y += metrics.Height + _paragraphs[index].SpaceAfter; } } } }
public void SciterPoint_set_width_and_height_from_property(float minWidth, float maxWidth, float height, float ascent, float descent, int noLines) { var actual = new TextMetrics { Ascent = ascent, Descent = descent, Height = height, LineCount = noLines, MaxWidth = maxWidth, MinWidth = minWidth, }; Assert.AreEqual(ascent, actual.Ascent); Assert.AreEqual(descent, actual.Descent); Assert.AreEqual(height, actual.Height); Assert.AreEqual(noLines, actual.LineCount); Assert.AreEqual(maxWidth, actual.MaxWidth); Assert.AreEqual(minWidth, actual.MinWidth); }
/// <summary> /// /// </summary> /// <param name="directWriteFactory"></param> /// <param name="text"></param> /// <param name="textFormat"></param> /// <param name="textColor"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="center"></param> public Label(SharpDX.DirectWrite.Factory directWriteFactory, string text, TextFormat textFormat, SolidColorBrush textColor, float x, float y, float width, float height, bool center = false) { TextColor = textColor; Text = text; Centered = center; TextFormat = textFormat; TextLayout = new TextLayout(directWriteFactory, text, textFormat, width, height); TextLayout.ParagraphAlignment = ParagraphAlignment.Near; TextMetrics textMetrics = TextLayout.Metrics; if (center) { TextPosition = new Vector2(x - (textMetrics.Width / 2f), y - (textMetrics.Height / 2f)); } else { TextPosition = new Vector2(x, y); } }
static void Main(string[] args) { var messages = new TextMessages(); var repo = new TextRepository(); var metrics = new TextMetrics(); Console.WriteLine("Listening for ExchangeTextRankTask event, press Ctrl+C to stop..."); messages.ConsumeMessagesInLoop(TextMessages.QueueVowelConsCounter, TextMessages.ExchangeTextRankTask, (model, id) => { try { string text = repo.GetText(id); int vowelCount = metrics.GetVowelCount(text); int consCount = metrics.GetConsonantsCount(text); messages.SendTextScoreTask(id, vowelCount, consCount); Console.WriteLine(id + " vowel count: " + vowelCount + ", cons count: " + consCount); } catch (Exception ex) { Console.WriteLine("exception occured: " + ex.ToString()); } }); }
static void Main(string[] args) { int remainingAccepts = processingLimit; var messages = new TextMessages(); var repo = new TextRepository(); var metrics = new TextMetrics(); Console.WriteLine("Listening for ExchangeText/ExchangeTextSuccessMarked events, press Ctrl+C to stop..."); using (var connection = messages.CreateConnection()) using (var channel = connection.CreateModel()) { messages.ListenMessages(channel, TextMessages.QueueTextProcessingLimiter, TextMessages.ExchangeText, (model, id) => { Console.WriteLine("captured text '" + repo.GetText(id) + "' with id=" + id); bool accepted = false; if (remainingAccepts > 0) { --remainingAccepts; accepted = true; } repo.SetTextStatus(id, accepted ? TextStatus.Accepted : TextStatus.Rejected); messages.SendProcessingAccepted(id, accepted); }); messages.ListenMessages(channel, TextMessages.QueueTextProcessingLimiterRevoke, TextMessages.ExchangeTextSuccessMarked, (model, json) => { var message = TextSuccessMarkedMessage.FromJson(json); repo.SetTextStatus(message.ContextId, TextStatus.Ready); Console.WriteLine("revoke transaction for successful text '" + repo.GetText(message.ContextId) + "' with id=" + message.ContextId); if (message.Success) { ++remainingAccepts; } }); while (true) { Thread.Sleep(Timeout.Infinite); } } }
public void TextMetrics_Ctor_Default() { var metric = new TextMetrics(); Assert.Equal(0, metric.Ascent); Assert.Equal(0, metric.AverageCharWidth); Assert.Equal('\0', metric.BreakChar); Assert.Equal(TextMetricsCharacterSet.Ansi, metric.CharSet); Assert.Equal('\0', metric.DefaultChar); Assert.Equal(0, metric.Descent); Assert.Equal(0, metric.DigitizedAspectX); Assert.Equal(0, metric.DigitizedAspectY); Assert.Equal(0, metric.ExternalLeading); Assert.Equal('\0', metric.FirstChar); Assert.Equal(0, metric.Height); Assert.Equal(0, metric.InternalLeading); Assert.False(metric.Italic); Assert.Equal(0, metric.MaxCharWidth); Assert.Equal(0, metric.Overhang); Assert.Equal((TextMetricsPitchAndFamilyValues)0, metric.PitchAndFamily); Assert.False(metric.StruckOut); Assert.False(metric.Underlined); Assert.Equal(0, metric.Weight); }
public static extern int GetTextMetrics(IntPtr DC, ref TextMetrics Metrics);
public static extern int GetThemeTextMetrics(HandleRef hTheme, HandleRef hdc, int iPartId, int iStateId, ref TextMetrics ptm);
public unsafe static HRESULT GetThemeTextMetrics(IHandle hTheme, HandleRef hdc, int iPartId, int iStateId, out TextMetrics ptm) { HRESULT hr = GetThemeTextMetrics(hTheme.Handle, hdc.Handle, iPartId, iStateId, out ptm); GC.KeepAlive(hTheme); GC.KeepAlive(hdc.Wrapper); return(hr); }