protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); if (Data == null) { return; } ComputeGlyphRuns(); GlyphRun gr; gr = glyphRuns[0]; if (gr != null) { drawingContext.DrawGlyphRun(TextColor, gr); } gr = glyphRuns[1]; if (gr != null) { drawingContext.DrawGlyphRun(DarkTextColor, gr); } gr = glyphRuns[2]; if (gr != null) { drawingContext.DrawGlyphRun(HighlightColor, gr); } glyphRuns = null; }
/// <inheritdoc/> public override void Draw(DrawingContext drawingContext, Point origin) { if (GlyphRun.GlyphIndices.Length == 0) { return; } if (Properties.Typeface == null) { return; } if (Properties.ForegroundBrush == null) { return; } if (Properties.BackgroundBrush != null) { drawingContext.DrawRectangle(Properties.BackgroundBrush, null, new Rect(origin.X, origin.Y + FontMetrics.Ascent, Bounds.Width, Bounds.Height)); } drawingContext.DrawGlyphRun(Properties.ForegroundBrush, GlyphRun, origin); if (Properties.TextDecorations == null) { return; } foreach (var textDecoration in Properties.TextDecorations) { textDecoration.Draw(drawingContext, this, origin); } }
private void DrawClusterPriceBarBg(/*double price, int amount*/ CCluster clusterData, double y, DateTime dtInterval, double actualWidthClusterGrid) { GenClusterBrushPen(clusterData, dtInterval); //calculate width of cluster bar long dealsAmountFullBar = CUtilConv.GetIntVolume(Math.Max(_dealsAmountFullBar, 1), _decimalVolume);//zero devide protect _volumeRectWidth = (((double)clusterData.AmountTotal) / ((double)dealsAmountFullBar)) * actualWidthClusterGrid; //draw cluster bar with proportional width //DrawRectangle(_brushCluster, _penCluster, new Rect(0.0, y, _volumeRectWidth, (double)_stirngHeight)); _drwCntxtClustersBg.DrawRectangle(_brushCluster, _penCluster, new Rect(0.0, y, _volumeRectWidth, (double)_stirngHeight)); // FormattedText(text, _cultureInfoDefault, FlowDirection.LeftToRight, _typeFaceDefault, _fontSizeScaled, brush); //2018-02-21 string stAmount = CTerminalUtil.GetAmount(clusterData.AmountTotal, _decimalVolume); //print cluster amount //DrawText(_FrmTxtCurrClustAmount, new Point(0.0, y)); //KAA 2017-03-01 changed to Glyph //2018-05-01 changed to fontsizeScaled GlyphRun gr = _glyphGenBg.GetGlyph(0, y + _fontSizeScaled, _fontSizeScaled, " " + /*clusterData.AmountTotal.ToString()*/ stAmount); _drwCntxtClustersBg.DrawGlyphRun(_brushFontBg, gr); }
protected void DrawText(DrawingContext dc, string text, Point location, SolidColorBrush color, double maxWidth) { if (text.Length > 0) { double totalWidth = 0; MGlyphIndexesList.Clear(); MAdvanceWidthsList.Clear(); foreach (char c in text) { if (totalWidth < maxWidth) { var info = MGlyphInfoTable[c]; MGlyphIndexesList.Add(info.Index); MAdvanceWidthsList.Add(info.Width); totalWidth += info.Width; } } if (MGlyphIndexesList.Count > 0) { GlyphRun glyphRun = new GlyphRun(GlyphTypeface, 0, false, FontSize, PixelsPerDip, MGlyphIndexesList.ToArray(), location, MAdvanceWidthsList.ToArray(), null, null, null, null, null, null); dc.DrawGlyphRun(color, glyphRun); } } }
public static void AddCharacterGlyph(this DrawingVisualHost visualHost, Point position, string character, bool isSmall = false, Brush color = null) { Brush characterColor = color ?? Brushes.Black; DrawingVisual visual = new DrawingVisual(); ushort glyphIndex = character.GetGlyphIndexOfCharacter(); PageProperties pageProperties = (PageProperties)ViewModel.ViewModelLocator.Instance.Main.CurrentPageLayout; GlyphTypeface gtf; Typeface typeFace = TypeFaces.BravuraMusicFont; typeFace.TryGetGlyphTypeface(out gtf); double smallFactor = isSmall ? 0.7 : 1; Point calculatedPosition = new Point(position.X, position.Y /* + pageProperties.IndexStaffLinePositions[3]*/); double characterSize = pageProperties.StaffHeight.MMToWPFUnit() * smallFactor; using (DrawingContext dc = visual.RenderOpen()) { GlyphRun gr = new GlyphRun(gtf, 0, // Bi-directional nesting level false, // isSideways characterSize, // pt size new ushort[] { glyphIndex }, // glyphIndices calculatedPosition, // baselineOrigin new double[] { 0.0 }, // advanceWidths null, // glyphOffsets null, // characters null, // deviceFontName null, // clusterMap null, // caretStops null); // xmlLanguage dc.DrawGlyphRun(characterColor, gr); } visualHost.AddVisual(visual); }
public override void Draw(DrawingContext drawingContext, double scale, double x, double y) { GlyphRun glyphRun = GetGlyphRun(scale, x, y); // Draw character at given position. drawingContext.DrawGlyphRun(this.Foreground ?? Brushes.Black, glyphRun); }
/// <inheritdoc/> public override void Draw(DrawingContext drawingContext) { if (GlyphRun.GlyphIndices.Length == 0) { return; } if (Properties.Typeface == default) { return; } if (Properties.ForegroundBrush == null) { return; } if (Properties.BackgroundBrush != null) { drawingContext.DrawRectangle(Properties.BackgroundBrush, null, new Rect(Size)); } drawingContext.DrawGlyphRun(Properties.ForegroundBrush, GlyphRun); if (Properties.TextDecorations == null) { return; } foreach (var textDecoration in Properties.TextDecorations) { textDecoration.Draw(drawingContext, this); } }
public static void DrawCharacterGlyph(DrawingVisual visual, Point position, ushort glyphIndex, bool isSmall = false) { PageProperties pageProperties = (PageProperties)ViewModel.ViewModelLocator.Instance.Main.CurrentPageLayout; double test = glyphIndex == 70? pageProperties.TenthToPx(3 * pageProperties.StaffSpace) : pageProperties.TenthToPx(1 * pageProperties.StaffSpace); //? temp //! ^^ measure lines - clef line property * staffspace(gets length from top line to choosen line) eg. clef line 4 == 5-4= 1*staffspace ==> 1staffspace from top GlyphTypeface gtf; Typeface typeFace = TypeFaces.BravuraMusicFont; typeFace.TryGetGlyphTypeface(out gtf); double smallFactor = isSmall ? 0.7 : 1; Point calculatedPosition = new Point(position.X, position.Y /** PageProperties.PxPerMM()*/); double characterSize = pageProperties.StaffHeight.MMToWPFUnit() * smallFactor; using (DrawingContext dc = visual.RenderOpen()) { GlyphRun gr = new GlyphRun(gtf, 0, // Bi-directional nesting level false, // isSideways characterSize, // pt size new ushort[] { glyphIndex }, // glyphIndices calculatedPosition, // baselineOrigin new double[] { 0.0 }, // advanceWidths null, // glyphOffsets null, // characters null, // deviceFontName null, // clusterMap null, // caretStops null); // xmlLanguage dc.DrawGlyphRun(Brushes.Black, gr); } }
public static double DrawString(DrawingContext dc, string text, string fontFamilyName, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch, int fontSize, Brush colorBrush, Point location) { Typeface typeface = new Typeface(new FontFamily(fontFamilyName), fontStyle, fontWeight, fontStretch); GlyphTypeface glyphTypeface; if (!typeface.TryGetGlyphTypeface(out glyphTypeface)) { return(0); } ushort[] glyphIndexes = new ushort[text.Length]; double[] advanceWidths = new double[text.Length]; double totalWidth = 0; for (int n = 0; n < text.Length; n++) { ushort glyphIndex = glyphTypeface.CharacterToGlyphMap[text[n]]; glyphIndexes[n] = glyphIndex; double width = glyphTypeface.AdvanceWidths[glyphIndex] * fontSize; advanceWidths[n] = width; totalWidth += width; } GlyphRun glyphRun = new GlyphRun(glyphTypeface, 0, false, fontSize, glyphIndexes, location, advanceWidths, null, null, null, null, null, null); dc.DrawGlyphRun(colorBrush, glyphRun); return(totalWidth); }
private void DrawHorizontalLinesText(DrawingContext dc, double initialPos, double stepSize) { double previousTextPos = initialPos; while (initialPos < MaxY) { initialPos += stepSize; System.Windows.Point p0 = new System.Windows.Point(MinX, initialPos); p0 = CurveCoordsToScreen(ref p0); p0.Y = Math.Truncate(p0.Y); if (Math.Abs(p0.Y - previousTextPos) > 20) { p0.Y = Math.Truncate(p0.Y) + 0.5; // Draw the tick System.Windows.Point p1 = new System.Windows.Point(0, p0.Y); p0 = new System.Windows.Point(3, p0.Y); dc.DrawLine(gridLinePen, p0, p1); p0.Y = Math.Truncate(p0.Y); glyphs.UnicodeString = String.Format("{0:0.###}", initialPos); glyphs.OriginX = 4; glyphs.OriginY = p0.Y + 5; dc.DrawGlyphRun(textBrush, glyphs.ToGlyphRun()); previousTextPos = p0.Y; } } }
protected override void OnRender(DrawingContext dc) { dc.DrawRectangle(Background, null, new Rect(RenderSize)); this.VisualTextRenderingMode = TextRenderingMode.ClearType; this.VisualTextHintingMode = TextHintingMode.Fixed; this.UseLayoutRounding = true; if (Items == null) { return; } try { double sizeNormal = Settings.Instance.FontSize; double sizeTitle = Settings.Instance.FontSizeTitle; foreach (ProgramViewItem info in Items) { dc.DrawRectangle(Brushes.LightGray, null, new Rect(info.LeftPos, info.TopPos, info.Width, info.Height)); if (info.Height > 2) { dc.DrawRectangle(info.ContentColor, null, new Rect(info.LeftPos + 1, info.TopPos + 1, info.Width - 2, info.Height - 2)); } } foreach (TextDrawItem info in textDrawList) { dc.DrawGlyphRun(info.FontColor, info.Text); } } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } }
/// <summary> /// Writes a string to a DrawingContext, using the GlyphTypeface stored in the GlyphDrawer. /// </summary> /// <param name="drawingContext"></param> /// <param name="origin"></param> /// <param name="text"></param> /// <param name="size">same unit like FontSize: (em)</param> /// <param name="brush"></param> public void Write(DrawingContext drawingContext, Point origin, string text, double size, Brush brush) { if (string.IsNullOrEmpty(text)) { return; } ushort[] glyphIndexes = new ushort[text.Length]; double[] advanceWidths = new double[text.Length]; double totalWidth = 0; for (int charIndex = 0; charIndex < text.Length; charIndex++) { ushort glyphIndex = glyphTypeface.CharacterToGlyphMap[text[charIndex]]; glyphIndexes[charIndex] = glyphIndex; double width = glyphTypeface.AdvanceWidths[glyphIndex] * size; advanceWidths[charIndex] = width; totalWidth += width; } GlyphRun glyphRun = new GlyphRun(glyphTypeface, 0, false, size, PixelsPerDip, glyphIndexes, origin, advanceWidths, null, null, null, null, null, null); drawingContext.DrawGlyphRun(brush, glyphRun); }
private void DrawVerticalLinesText(DrawingContext dc, double initialPos, double stepSize) { double previousTextPos = initialPos; while (initialPos < MaxX) { initialPos += stepSize; System.Windows.Point p0 = new System.Windows.Point(initialPos, MinY); p0 = CurveCoordsToScreen(ref p0); p0.X = Math.Truncate(p0.X); if (Math.Abs(p0.X - previousTextPos) > 40) { p0.X = Math.Truncate(p0.X) + 0.5; // Draw the tick System.Windows.Point p1 = new System.Windows.Point(p0.X, ActualHeight); p0 = new System.Windows.Point(p0.X, ActualHeight - 3); dc.DrawLine(gridLinePen, p0, p1); p0.X = Math.Truncate(p0.X - 3); glyphs.UnicodeString = String.Format("{0:0.###}", initialPos); glyphs.OriginX = p0.X; glyphs.OriginY = 12; dc.DrawGlyphRun(textBrush, glyphs.ToGlyphRun()); previousTextPos = p0.X; } } }
public static void Render(DrawingContext dc, CanvasData cd) { foreach (var data in _dataStore) { switch (data.Type) { case DrawType.Elipse: foreach (var point in data.Points) { dc.DrawEllipse(GetBrush(data.Color), null, point.ToCanvasPoint(), DebugDrawSize, DebugDrawSize); } break; case DrawType.PolyLine: var points = RadarCanvas.GrahamScan.GrahamScanCompute(data.Points).Select(p => p.ToCanvasPoint()); dc.DrawPolygon(points, GetBrush(data.Color)); break; case DrawType.Text: var txtPos = data.Points.First().ToCanvasPoint(); txtPos.Y += 15; var gr = DrawingUtilities.CreateGlyphRun(data.Name, 10, txtPos); dc.DrawGlyphRun(GetBrush(data.Color), gr); break; } } }
protected override void OnRender(DrawingContext drawingContext) { DrawingContext dc = drawingContext; Typeface typeface = new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal); GlyphTypeface glyphTypeface; if (!typeface.TryGetGlyphTypeface(out glyphTypeface)) { throw new InvalidOperationException("No glyphtypeface found"); } string text = "Hello, world!"; double size = 40; ushort[] glyphIndexes = new ushort[text.Length]; double[] advanceWidths = new double[text.Length]; double totalWidth = 0; for (int n = 0; n < text.Length; n++) { ushort glyphIndex = glyphTypeface.CharacterToGlyphMap[text[n]]; glyphIndexes[n] = glyphIndex; double width = glyphTypeface.AdvanceWidths[glyphIndex] * size; advanceWidths[n] = width; totalWidth += width; } Point origin = new Point(100, 500); GlyphRun glyphRun = new GlyphRun(glyphTypeface, 0, false, size, glyphIndexes, origin, advanceWidths, null, null, null, null, null, null); dc.DrawGlyphRun(Brushes.Black, glyphRun); /* * double y = origin.Y; * dc.DrawLine(new Pen(Brushes.Red, 1), new Point(origin.X, y), * new Point(origin.X + totalWidth, y)); * * y -= (glyphTypeface.Baseline * size); * dc.DrawLine(new Pen(Brushes.Green, 1), new Point(origin.X, y), * new Point(origin.X + totalWidth, y)); * * y += (glyphTypeface.Height * size); * dc.DrawLine(new Pen(Brushes.Blue, 1), new Point(origin.X, y), * new Point(origin.X + totalWidth, y)); */ base.OnRender(drawingContext); }
protected override void OnRender(DrawingContext dc) { dc.DrawRectangle(Background, null, new Rect(RenderSize)); if (Items != null && textDrawLists != null && Items.Count >= textDrawLists.Count && ContentBrushList != null && ContentBrushList.Count >= 17) { double selfLeft = Canvas.GetLeft(this); Brush bgBrush = Background; Brush filteredBrush = null; if (bgBrush is SolidColorBrush) { Color c = ((SolidColorBrush)bgBrush).Color; filteredBrush = new SolidColorBrush(Color.FromArgb(FilteredAlpha, c.R, c.G, c.B)); filteredBrush.Freeze(); } //位置がずれないように枠線の幅が1より大きいときは両側で分け合う double borderLeft = _borderLeftSize > 1 ? _borderLeftSize / 2 : _borderLeftSize; double borderTop = _borderTopSize > 1 ? _borderTopSize / 2 : _borderTopSize; for (int i = 0; i < textDrawLists.Count; i++) { ProgramViewItem info = Items[i]; double bgHeight = Math.Min(borderTop, info.Height); if (info.Width > _borderLeftSize && bgHeight > 0) { dc.DrawRectangle(bgBrush, null, new Rect(info.LeftPos + borderLeft - selfLeft, info.TopPos, info.Width - _borderLeftSize, bgHeight)); dc.DrawRectangle(bgBrush, null, new Rect(info.LeftPos + borderLeft - selfLeft, info.TopPos + info.Height - bgHeight, info.Width - _borderLeftSize, bgHeight)); } if (info.Width > _borderLeftSize && info.Height > _borderTopSize) { Brush contentBrush = ContentBrushList[0x10]; if (info.EventInfo.ContentInfo != null) { foreach (EpgContentData nibble in info.EventInfo.ContentInfo.nibbleList) { if (nibble.content_nibble_level_1 <= 0x0B || nibble.content_nibble_level_1 == 0x0F) { contentBrush = ContentBrushList[nibble.content_nibble_level_1]; break; } } } var textArea = new Rect(info.LeftPos + borderLeft - selfLeft, info.TopPos + borderTop, info.Width - _borderLeftSize, info.Height - _borderTopSize); dc.DrawRectangle(contentBrush, null, textArea); dc.PushClip(new RectangleGeometry(textArea)); foreach (Tuple <Brush, GlyphRun> txtinfo in textDrawLists[i]) { dc.DrawGlyphRun(txtinfo.Item1, txtinfo.Item2); } dc.Pop(); if (info.Filtered && filteredBrush != null) { dc.DrawRectangle(filteredBrush, null, textArea); } } } } }
protected override void OnRender(DrawingContext dc) { Brush bgBrush = Background; dc.DrawRectangle(bgBrush, null, new Rect(RenderSize)); if (Items == null) { return; } try { //long tickStart = DateTime.Now.Ticks; //パフォーマンス計測用 double selfLeft = Canvas.GetLeft(this); // Items 設定時に CreateDrawTextList を行うと、番組表に複数のタブを設定していると // 全てのタブの GlyphRun を一度に生成しようとするので、最初の表示までに多くの時間がかかる。 // 表示しようとするタブのみ GlyphRun を行うことで、最初の応答時間を削減することにする。 CreateDrawTextList(); //long tickGlyphRun = DateTime.Now.Ticks; //パフォーマンス計測用 foreach (ProgramViewItem info in Items) { dc.DrawRectangle(bgBrush, null, new Rect(info.LeftPos - selfLeft, info.TopPos, info.Width, 1)); dc.DrawRectangle(bgBrush, null, new Rect(info.LeftPos - selfLeft, info.TopPos + info.Height, info.Width, 1)); if (info.Height > 1) { dc.DrawRectangle(info.ContentColor, null, new Rect(info.LeftPos - selfLeft, info.TopPos + 0.5, info.Width - 1, info.Height - 0.5)); if (textDrawDict.ContainsKey(info)) { dc.PushClip(new RectangleGeometry(new Rect(info.LeftPos - selfLeft, info.TopPos + 0.5, info.Width - 1, info.Height - 0.5))); foreach (TextDrawItem txtinfo in textDrawDict[info]) { dc.DrawGlyphRun(txtinfo.FontColor, txtinfo.Text); } dc.Pop(); } } } // EpgViewPanel は複数に分けて Render するので、最後のパネルが Render し終わったら // 些細なメモリ節約のために cache をクリアする ItemFontNormal.ClearCache(); ItemFontTitle.ClearCache(); //パフォーマンス計測用 //long tickDraw = DateTime.Now.Ticks; //Console.Write("GlyphRun = " + Math.Round((tickGlyphRun - tickStart)/10000D).ToString() // + ", Draw = " + Math.Round((tickDraw - tickGlyphRun)/10000D).ToString() // + ", Total = " + Math.Round((tickDraw-tickStart)/10000D).ToString() + "\n"); } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } }
protected override void OnRender(DrawingContext drawingContext) { var fontFamily = new FontFamily("微软雅黑"); var fontSize = 15; var y = 0; drawingContext.PushOpacity(0.3); foreach (var typeface in fontFamily.GetTypefaces().Skip(1).Take(1)) { double offset = 3; var baseLine = fontFamily.GetBaseline(fontSize); if (typeface.TryGetGlyphTypeface(out var glyphTypeface)) { foreach (var c in Text) { if (glyphTypeface.CharacterToGlyphMap.TryGetValue(c, out var glyphIndex)) { var width = glyphTypeface.AdvanceWidths[glyphIndex] * fontSize; width = GlyphExtension.RefineValue(width); #pragma warning disable 618 // 忽略调用废弃构造函数 var glyphRun = new GlyphRun( #pragma warning restore 618 glyphTypeface, 0, false, fontSize, new[] { glyphIndex }, new Point(offset, baseLine + y), new[] { width }, DefaultGlyphOffsetArray, new char[] { c }, null, null, null, DefaultXmlLanguage); drawingContext.DrawLine(new Pen(Brushes.Black, 2), new Point(offset, y), new Point(offset + width, y)); drawingContext.DrawGlyphRun(Brushes.Coral, glyphRun); var glyphSize = glyphRun.GetSize(fontFamily.LineSpacing); drawingContext.DrawRectangle(null, new Pen(Brushes.Black, 2), new Rect(new Point(offset, y), glyphSize)); offset += width; } } } y += fontSize; } drawingContext.Pop(); }
protected override void OnRender(DrawingContext drawingContext) { foreach (MyText text in texts) { drawingContext.PushTransform(new TranslateTransform(text.Position.X, text.Position.Y)); drawingContext.DrawGlyphRun(text.brush, text.run); drawingContext.Pop(); } Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(delegate { OnFrameRendered(EventArgs.Empty); })); }
public void RenderGlyph(DrawingContext dc, ushort gid, Point origin, double size, Brush fallback_brush) { ushort layer_index; if (m_openfont.COLRTable != null && m_openfont.CPALTable != null && m_openfont.COLRTable.LayerIndices.TryGetValue(gid, out layer_index)) { int start = layer_index, stop = layer_index + m_openfont.COLRTable.LayerCounts[gid]; int palette = 0; // FIXME: support multiple palettes? for (int i = start; i < stop; ++i) { ushort sub_gid = m_openfont.COLRTable.GlyphLayers[i]; // We do not need to provide advances since we only render one glyph. GlyphRun r = new GlyphRun(m_gtf, 0, false, size, new ushort[] { sub_gid }, origin, new double[] { 0 }, null, null, null, // FIXME: check what this is? null, null, null); int cid = m_openfont.CPALTable.Palettes[palette] + m_openfont.COLRTable.GlyphPalettes[i]; byte R, G, B, A; m_openfont.CPALTable.GetColor(cid, out R, out G, out B, out A); if (fallback_brush is SolidColorBrush brush) { R = (byte)(R + (255 - R) * brush.Color.R / 255); G = (byte)(G + (255 - G) * brush.Color.G / 255); B = (byte)(B + (255 - B) * brush.Color.B / 255); } Brush b = new SolidColorBrush(Color.FromArgb(A, R, G, B)); dc.DrawGlyphRun(b, r); } } else { GlyphRun r = new GlyphRun(m_gtf, 0, false, size, new ushort[] { gid }, origin, new double[] { 0 }, null, null, null, null, null, null); dc.DrawGlyphRun(fallback_brush, r); } }
protected override void OnRender(DrawingContext drawingContext) { if (CheckGlyphRun()) { var location = outline.Bounds.Location; drawingContext.PushTransform(new TranslateTransform(-location.X, -location.Y)); drawingContext.DrawGeometry(Background, null, outline); drawingContext.DrawGlyphRun(Foreground, glyphRun); } }
public override void Draw(DrawingContext drawingContext, double scale, double x, double y) { // Draw character at given position. var typeface = Character.Font; var glyphIndex = typeface.CharacterToGlyphMap[Character.Character]; var glyphRun = new GlyphRun(typeface, 0, false, Character.Size * scale, new[] { glyphIndex }, new Point(x * scale, y * scale), new[] { typeface.AdvanceWidths[glyphIndex] }, null, null, null, null, null, null); drawingContext.DrawGlyphRun(Foreground ?? Brushes.Black, glyphRun); }
public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl) { var colorConv = ((BrushAdapter)_adapter.GetSolidBrush(color)).Brush; bool glyphRendered = false; GlyphTypeface glyphTypeface = ((FontAdapter)font).GlyphTypeface; if (glyphTypeface != null) { double width = 0; ushort[] glyphs = new ushort[str.Length]; double[] widths = new double[str.Length]; int i = 0; for (; i < str.Length; i++) { ushort glyph; if (!glyphTypeface.CharacterToGlyphMap.TryGetValue(str[i], out glyph)) { break; } glyphs[i] = glyph; width += glyphTypeface.AdvanceWidths[glyph]; widths[i] = 96d / 72d * font.Size * glyphTypeface.AdvanceWidths[glyph]; } if (i >= str.Length) { point.Y += glyphTypeface.Baseline * font.Size * 96d / 72d; point.X += rtl ? 96d / 72d * font.Size * width : 0; glyphRendered = true; var wpfPoint = Utils.ConvertRound(point); var glyphRun = new GlyphRun(glyphTypeface, rtl ? 1 : 0, false, 96d / 72d * font.Size, glyphs, wpfPoint, widths, null, null, null, null, null, null); var guidelines = new GuidelineSet(); guidelines.GuidelinesX.Add(wpfPoint.X); guidelines.GuidelinesY.Add(wpfPoint.Y); _g.PushGuidelineSet(guidelines); _g.DrawGlyphRun(colorConv, glyphRun); _g.Pop(); } } if (!glyphRendered) { var formattedText = new FormattedText(str, CultureInfo.CurrentCulture, rtl ? FlowDirection.RightToLeft : FlowDirection.LeftToRight, ((FontAdapter)font).Font, 96d / 72d * font.Size, colorConv); point.X += rtl ? formattedText.Width : 0; _g.DrawText(formattedText, Utils.ConvertRound(point)); } }
public override void Draw(DrawingContext drawingContext, Point origin, InvertAxes inversion) { foreach (var entry in entries) { if (entry.Item2 == null) { continue; } if (entry.Item3 == entry.Item1.Length) // All whitespace, no need to render { continue; } var textRun = entry.Item1; var glyphRun = entry.Item2; var textProps = textRun.Properties; var newRun = Clone(glyphRun, new Point { X = origin.X + glyphRun.BaselineOrigin.X, Y = (int)(origin.Y + glyphRun.GlyphTypeface.Baseline * textProps.FontRenderingEmSize) }); if (_textFormattingMode != null) { _textFormattingMode.SetValue(glyphRun, mode); } var box = newRun.ComputeAlignmentBox(); if (textProps.BackgroundBrush != null) { drawingContext.DrawRectangle( textProps.BackgroundBrush, null, new Rect(origin, box.Size)); } drawingContext.DrawGlyphRun(textProps.ForegroundBrush, newRun); if (textProps.TextDecorations != null) { foreach (var deco in textProps.TextDecorations) { var thickness = Math.Round(glyphRun.GlyphTypeface.UnderlineThickness * textProps.FontRenderingEmSize); var pos = glyphRun.GlyphTypeface.UnderlinePosition - glyphRun.GlyphTypeface.Baseline + glyphRun.GlyphTypeface.Height; pos = Math.Round(pos * textProps.FontRenderingEmSize) + thickness / 2; var pen = new Pen(textProps.ForegroundBrush, thickness); drawingContext.DrawLine(pen, new Point(newRun.BaselineOrigin.X, newRun.BaselineOrigin.Y + pos), new Point(newRun.BaselineOrigin.X + box.Width, newRun.BaselineOrigin.Y + pos)); } } } }
public override void Perform() { DrawingContext Target = SetDrawingContext(); //Draws the specified text. Target.DrawGlyphRun(Brush, GlyphRun); Target.Close(); //Add DrawingGroup to DrawingBrush's Drawing property ((DrawingBrush)(Control.Background)).Drawing = DrawingGroup; }
private static void drawGlyph(DrawingContext dc, string text) { Typeface typeface = new Typeface(new FontFamily("Arial"), FontStyles.Italic, FontWeights.Normal, FontStretches.Normal); GlyphTypeface glyphTypeface; if (!typeface.TryGetGlyphTypeface(out glyphTypeface)) { throw new InvalidOperationException("No glyphtypeface found"); } double size = 40; ushort[] glyphIndexes = new ushort[text.Length]; double[] advanceWidths = new double[text.Length]; double totalWidth = 0; for (int n = 0; n < text.Length; n++) { ushort glyphIndex = glyphTypeface.CharacterToGlyphMap[text[n]]; glyphIndexes[n] = glyphIndex; double width = glyphTypeface.AdvanceWidths[glyphIndex] * size; advanceWidths[n] = width; totalWidth += width; } Point origin = new Point(50, 50); GlyphRun glyphRun = new GlyphRun(glyphTypeface, 0, false, size, glyphIndexes, origin, advanceWidths, null, null, null, null, null, null); dc.DrawGlyphRun(Brushes.Black, glyphRun); double y = origin.Y; dc.DrawLine(new Pen(Brushes.Red, 1), new Point(origin.X, y), new Point(origin.X + totalWidth, y)); y -= (glyphTypeface.Baseline * size); dc.DrawLine(new Pen(Brushes.Green, 1), new Point(origin.X, y), new Point(origin.X + totalWidth, y)); y += (glyphTypeface.Height * size); dc.DrawLine(new Pen(Brushes.Blue, 1), new Point(origin.X, y), new Point(origin.X + totalWidth, y)); }
protected override void OnRender(DrawingContext dc) { base.OnRender(dc); var typeface = new Typeface(FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); if (typeface.TryGetGlyphTypeface(out var gtf)) { var iconSymbol = (char)(int)(ValueType)(Icon); var glyph = ConvertTextLinesToGlyphRun(gtf, Size, iconSymbol); dc.DrawGlyphRun(Foreground, glyph); } }
private DrawingVisual RenderDrops() { DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); drawingContext.DrawRectangle(BackgroundBrush, null, CanvasRect); List <ushort> glyphIndices = new List <ushort>(); List <double> advancedWidths = new List <double>(); List <Point> glyphOffsets = new List <Point>(); for (var i = 0; i < Drops.Length; i++) { double x = BaselineOrigin.X + LetterAdvanceWidth * i; double y = BaselineOrigin.Y + LetterAdvanceHeight * Drops[i]; if (y + LetterAdvanceHeight < CanvasRect.Height) { var glyphIndex = GlyphTypeface.CharacterToGlyphMap[AvaiableLetterChars[CryptoRandom.Next(0, AvaiableLetterChars.Length - 1)]]; glyphIndices.Add(glyphIndex); advancedWidths.Add(0); glyphOffsets.Add(new Point(x, -y)); } if (Drops[i] * LetterAdvanceHeight > CanvasRect.Height && CryptoRandom.NextDouble() > 0.775) { Drops[i] = 0; } Drops[i]++; } if (glyphIndices.Count > 0) { float pixelsPerDip = (float)VisualTreeHelper.GetDpi(drawingVisual).PixelsPerDip; GlyphRun glyphRun = new GlyphRun( GlyphTypeface, 0, false, RenderingEmSize, pixelsPerDip, glyphIndices, BaselineOrigin, advancedWidths, glyphOffsets, null, null, null, null, null); drawingContext.DrawGlyphRun(TextBrush, glyphRun); } drawingContext.Close(); return(drawingVisual); }
// Token: 0x0600301A RID: 12314 RVA: 0x000D8690 File Offset: 0x000D6890 private void _UpdateHighlightForeground(DrawingContext dc, ArrayList highlights) { foreach (object obj in highlights) { FixedHighlight fixedHighlight = (FixedHighlight)obj; Brush brush = null; if (fixedHighlight.HighlightType != FixedHighlightType.None) { Glyphs glyphs = fixedHighlight.Glyphs; if (glyphs != null) { Rect rect = fixedHighlight.ComputeDesignRect(); if (!(rect == Rect.Empty)) { GeneralTransform generalTransform = fixedHighlight.Element.TransformToAncestor(this._page); Transform affineTransform = generalTransform.AffineTransform; if (affineTransform != null) { dc.PushTransform(affineTransform); } else { dc.PushTransform(Transform.Identity); } dc.PushClip(new RectangleGeometry(rect)); if (fixedHighlight.HighlightType == FixedHighlightType.TextSelection) { brush = SelectionHighlightInfo.ForegroundBrush; } else if (fixedHighlight.HighlightType == FixedHighlightType.AnnotationHighlight) { brush = fixedHighlight.ForegroundBrush; } GlyphRun glyphRun = glyphs.ToGlyphRun(); if (brush == null) { brush = glyphs.Fill; } dc.PushGuidelineY1(glyphRun.BaselineOrigin.Y); dc.PushClip(glyphs.Clip); dc.DrawGlyphRun(brush, glyphRun); dc.Pop(); dc.Pop(); dc.Pop(); dc.Pop(); } } } } }
public void DrawText(DrawingContext dc, string text, Point origin) { var indexes = new ushort[text.Length]; var widths = new double[text.Length]; for (int i = 0; i < text.Length; i++) { indexes[i] = _glyphFace.CharacterToGlyphMap[text[i]]; widths[i] = _glyphFace.AdvanceWidths[indexes[i]] * _fontSize; } var run = new GlyphRun(_glyphFace, 0, false, _fontSize, indexes, origin, widths, null, null, null, null, null, null); dc.DrawGlyphRun(Brushes.Black, run); }