private Rect DrawIndexedGlyphRun(DrawingContext drawingContext, IndexedGlyphRun indexedrun, Point linePosition, JapaneseTextSource source, bool isVerticalWriting) { GlyphRun run; if (isVerticalWriting) { List<double> advanceWidths = new List<double>(); int[] advance2 = source.Advance; for (int i = 0; i < advance2.Length; i++) { int advance = advance2[i]; advanceWidths.Add((double)advance); } run = new GlyphRun(indexedrun.GlyphRun.GlyphTypeface, indexedrun.GlyphRun.BidiLevel, true, indexedrun.GlyphRun.FontRenderingEmSize, source.Glyphs, linePosition, indexedrun.GlyphRun.AdvanceWidths, indexedrun.GlyphRun.GlyphOffsets, indexedrun.GlyphRun.Characters, indexedrun.GlyphRun.DeviceFontName, indexedrun.GlyphRun.ClusterMap, indexedrun.GlyphRun.CaretStops, indexedrun.GlyphRun.Language); } else { run = new GlyphRun(indexedrun.GlyphRun.GlyphTypeface, indexedrun.GlyphRun.BidiLevel, false, indexedrun.GlyphRun.FontRenderingEmSize, indexedrun.GlyphRun.GlyphIndices, linePosition, indexedrun.GlyphRun.AdvanceWidths, indexedrun.GlyphRun.GlyphOffsets, indexedrun.GlyphRun.Characters, indexedrun.GlyphRun.DeviceFontName, indexedrun.GlyphRun.ClusterMap, indexedrun.GlyphRun.CaretStops, indexedrun.GlyphRun.Language); } drawingContext.DrawGlyphRun(source.JapaneseTextRunProperties.ForegroundBrush, run); return run.ComputeAlignmentBox(); }
private Rect DrawIndexedGlyphRun(DrawingContext drawingContext, IndexedGlyphRun indexedrun, Point linePosition, JapaneseTextSource source, bool isVerticalWriting) { GlyphRun run; if (isVerticalWriting) { List <double> advanceWidths = new List <double>(); int[] advance2 = source.Advance; for (int i = 0; i < advance2.Length; i++) { int advance = advance2[i]; advanceWidths.Add((double)advance); } run = new GlyphRun(indexedrun.GlyphRun.GlyphTypeface, indexedrun.GlyphRun.BidiLevel, true, indexedrun.GlyphRun.FontRenderingEmSize, source.Glyphs, linePosition, indexedrun.GlyphRun.AdvanceWidths, indexedrun.GlyphRun.GlyphOffsets, indexedrun.GlyphRun.Characters, indexedrun.GlyphRun.DeviceFontName, indexedrun.GlyphRun.ClusterMap, indexedrun.GlyphRun.CaretStops, indexedrun.GlyphRun.Language); } else { run = new GlyphRun(indexedrun.GlyphRun.GlyphTypeface, indexedrun.GlyphRun.BidiLevel, false, indexedrun.GlyphRun.FontRenderingEmSize, indexedrun.GlyphRun.GlyphIndices, linePosition, indexedrun.GlyphRun.AdvanceWidths, indexedrun.GlyphRun.GlyphOffsets, indexedrun.GlyphRun.Characters, indexedrun.GlyphRun.DeviceFontName, indexedrun.GlyphRun.ClusterMap, indexedrun.GlyphRun.CaretStops, indexedrun.GlyphRun.Language); } drawingContext.DrawGlyphRun(source.JapaneseTextRunProperties.ForegroundBrush, run); return(run.ComputeAlignmentBox()); }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); Rect rect = new Rect(0.0, 0.0, base.ActualWidth, base.ActualHeight); JapaneseTextSource source = new JapaneseTextSource(); source.Text = this.Text; JapaneseTextParagraphProperties textParagraphProperties = this.MakeTextProperties(); source.JapaneseTextRunProperties = (JapaneseTextRunProperties)textParagraphProperties.DefaultTextRunProperties; source.IsVarticalWriting = textParagraphProperties.IsVerticalWriting; if (textParagraphProperties.DefaultTextRunProperties.BackgroundBrush != null) { drawingContext.DrawRectangle(textParagraphProperties.DefaultTextRunProperties.BackgroundBrush, null, rect); } Rect paddingRect = new Rect(this.Padding.Left, this.Padding.Top, Math.Max(0.0, base.ActualWidth - this.Padding.Left - this.Padding.Right), Math.Max(0.0, base.ActualHeight - this.Padding.Top - this.Padding.Bottom)); Point center = new Point((paddingRect.Left + paddingRect.Right) / 2.0, (paddingRect.Top + paddingRect.Bottom) / 2.0); Point startPosition; double paragraphWidth; if (textParagraphProperties.IsVerticalWriting) { Point origin = paddingRect.TopRight; Transform transOrigin = new RotateTransform(-90.0, center.X, center.Y); startPosition = transOrigin.Transform(origin); paragraphWidth = Math.Abs(paddingRect.Height); Transform trans = new RotateTransform(90.0, center.X, center.Y); drawingContext.PushTransform(trans); } else { startPosition = paddingRect.TopLeft; paragraphWidth = Math.Abs(paddingRect.Width); } startPosition.Y += textParagraphProperties.JapaneseTextRunProperties.FontRenderingEmSize; int textStorePosition = 0; Point linePosition = startPosition; TextFormatter formatter = TextFormatter.Create(); while (textStorePosition < source.Text.Length) { using (TextLine textLine = formatter.FormatLine(source, textStorePosition, paragraphWidth, textParagraphProperties, null)) { foreach (IndexedGlyphRun indexedrun in textLine.GetIndexedGlyphRuns()) { if (textParagraphProperties.IsVerticalWriting) { source.UniscribeIndexedGlyphRun(indexedrun); Rect runRect; if (source.GlyphCount != 0 && source.Glyphs[0] != 0) { Point ansiLinePosition = linePosition; ansiLinePosition.Y -= textParagraphProperties.JapaneseTextRunProperties.FontRenderingEmSize / 2.0; runRect = this.DrawIndexedGlyphRun(drawingContext, indexedrun, ansiLinePosition, source, true); } else { Point ansiLinePosition = linePosition; ansiLinePosition.Y -= textParagraphProperties.JapaneseTextRunProperties.FontRenderingEmSize / 10.0; runRect = this.DrawIndexedGlyphRun(drawingContext, indexedrun, ansiLinePosition, source, false); } linePosition.X += runRect.Width; } else { Rect runRect = this.DrawIndexedGlyphRun(drawingContext, indexedrun, linePosition, source, false); linePosition.X += runRect.Width; } } textStorePosition += textLine.Length; linePosition.X = startPosition.X; linePosition.Y += textLine.Height; } } if (textParagraphProperties.IsVerticalWriting) { drawingContext.Pop(); } }