简体   繁体   English

访问CustomTextParagraphProperties我需要参考什么?

[英]What do I need to reference to access CustomTextParagraphProperties?

Working with TextFormatter, I came accross this article on MSDN which shows the following sample code : 使用TextFormatter时,我在MSDN上看到了本文,其中显示了以下示例代码:

// Create a TextFormatter object.
TextFormatter formatter = TextFormatter.Create();

// Create common paragraph property settings.
CustomTextParagraphProperties customTextParagraphProperties
    = new CustomTextParagraphProperties();

// Format each line of text from the text store and draw it.
while (textStorePosition < customTextSource.Text.Length)
{
    // Create a textline from the text store using the TextFormatter object.
    using (TextLine myTextLine = formatter.FormatLine(
        customTextSource,
        textStorePosition,
        96 * 6,
        customTextParagraphProperties,
        null))
    {
        // Draw the formatted text into the drawing context.
        myTextLine.Draw(drawingContext, linePosition, InvertAxes.None);

        // Update the index position in the text store.
        textStorePosition += myTextLine.Length;

        // Update the line position coordinate for the displayed line.
        linePosition.Y += myTextLine.Height;
    }
}

The problem I am having is even after referencing System.Windows.Media.TextFormatting there is no class/object using CustomTextParagraphProperties so that line throws an error (of course since it doesn't exist) 我遇到的问题甚至是在引用System.Windows.Media.TextFormatting之后,没有使用CustomTextParagraphProperties类/对象,因此该行引发了错误(当然,因为它不存在)

What else do I need to reference to access this class ? 访问该类还需要参考什么?

This is my using list : 这是我的using清单:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Drawing.Printing;
using System.ComponentModel;
using System.Windows.Media.TextFormatting;
using System.IO;

And this is the list of my references: 这是我的参考文献清单:

参考资料

I found TextParagraphProperties but this is an abstract class and thus can not be created using new , meaning it isn't a drop in replacement for CustomTextParagraphProperties as the example shows, the following line would not work : 我找到了TextParagraphProperties但这是一个abstract类,因此无法使用new来创建,这意味着它不能代替CustomTextParagraphProperties如示例所示,以下行将无法工作:

TextParagraphProperties tp = new TextParagraphProperties();

NOTE: I added the WPF tag as this project inherits WPF functionality, but this is not a WPF project. 注意:我添加了WPF标记,因为该项目继承了WPF功能,但这不是WPF项目。

I started to delve down a rabbit hole, and finding more and more codependant abstract classes the parent depends upon, and since can't use the new to inistialize the object, must write a bunch of code, with no end in sight, this is rather frustrating : 我开始钻研一个兔子洞,找到了父依赖的越来越多的相互依赖的abstract类,并且由于不能使用new的实例化对象,因此必须编写一堆代码,而且看不到目的。相当令人沮丧:

#region textformatter
    class TextRunProperties : System.Windows.Media.TextFormatting.TextRunProperties {
        public override Windows.Media.Brush BackgroundBrush { get; set; }
        public override Windows.BaselineAlignment BaselineAlignment { get { return base.BaselineAlignment; } }
        public override CultureInfo CultureInfo { get; set; }
        public override double FontHintingEmSize { get; set; }
        public override double FontRenderingEmSize { get; set; }
        public override Windows.Media.Brush ForegroundBrush { get; set; }
        public override Windows.Media.NumberSubstitution NumberSubstitution { get { return base.NumberSubstitution; } }
        public override TextDecorationCollection TextDecorations { get; set; }
        public override Windows.Media.TextEffectCollection TextEffects { get; set; }
        public override Windows.Media.Typeface Typeface { get; set; }
        public override Windows.Media.TextFormatting.TextRunTypographyProperties TypographyProperties { get { return base.TypographyProperties; } }
    }

    class TextRun : System.Windows.Media.TextFormatting.TextRun {
        public override CharacterBufferReference CharacterBufferReference { get; set; }
        public override int Length { get; set; }
        public override Windows.Media.TextFormatting.TextRunProperties Properties { get; set; }
    }

    class TextSource : System.Windows.Media.TextFormatting.TextSource {
        public override Windows.Media.TextFormatting.TextSpan<CultureSpecificCharacterBufferRange> GetPrecedingText( int textSourceCharacterIndexLimit ) {
            return new TextSpan<CultureSpecificCharacterBufferRange>(
                textSourceCharacterIndexLimit,
                new CultureSpecificCharacterBufferRange(
                    new CultureInfo(0),
                    Windows.Media.TextFormatting.CharacterBufferRange.Empty
                )
            );
        }

        public override int GetTextEffectCharacterIndexFromTextSourceCharacterIndex( int textSourceCharacterIndex ) {
            return 0;
        }

        public override Windows.Media.TextFormatting.TextRun GetTextRun( int textSourceCharacterIndex ) {
            return new TextRun();
        }
    }

    class TextFormatter : System.Windows.Media.TextFormatting.TextFormatter {
        public override Windows.Media.TextFormatting.TextLine FormatLine( Windows.Media.TextFormatting.TextSource textSource, int firstCharIndex, double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak, TextRunCache textRunCache ) {
            throw new NotImplementedException();
        }

        public override Windows.Media.TextFormatting.TextLine FormatLine( Windows.Media.TextFormatting.TextSource textSource, int firstCharIndex, double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak ) {
            throw new NotImplementedException();
        }

        public override Windows.Media.TextFormatting.MinMaxParagraphWidth FormatMinMaxParagraphWidth( Windows.Media.TextFormatting.TextSource textSource, int firstCharIndex, TextParagraphProperties paragraphProperties ) {
            throw new NotImplementedException();
        }

        public override Windows.Media.TextFormatting.MinMaxParagraphWidth FormatMinMaxParagraphWidth( Windows.Media.TextFormatting.TextSource textSource, int firstCharIndex, TextParagraphProperties paragraphProperties, TextRunCache textRunCache ) {
            throw new NotImplementedException();
        }

    }

    class TextLine : System.Windows.Media.TextFormatting.TextLine {
        public override double Baseline {
            get { throw new NotImplementedException(); }
        }

        public override int DependentLength {
            get { throw new NotImplementedException(); }
        }

        public override double Extent {
            get { throw new NotImplementedException(); }
        }
        public override bool HasCollapsed {
            get { throw new NotImplementedException(); }
        }
        public override bool HasOverflowed {
            get { throw new NotImplementedException(); }
        }

        public override double Height {
            get { throw new NotImplementedException(); }
        }

        public override bool IsTruncated {
            get {
                return base.IsTruncated;
            }
        }

        public override int Length {
            get { throw new NotImplementedException(); }
        }

        public override double MarkerBaseline {
            get { throw new NotImplementedException(); }
        }
        public override double MarkerHeight {
            get { throw new NotImplementedException(); }
        }
        public override int NewlineLength {
            get { throw new NotImplementedException(); }
        }
        public override double OverhangAfter {
            get { throw new NotImplementedException(); }
        }
        public override double OverhangLeading {
            get { throw new NotImplementedException(); }
        }
        public override double OverhangTrailing {
            get { throw new NotImplementedException(); }
        }
        public override double Start {
            get { throw new NotImplementedException(); }
        }
        public override double TextBaseline {
            get { throw new NotImplementedException(); }
        }
        public override double TextHeight {
            get { throw new NotImplementedException(); }
        }
        public override int TrailingWhitespaceLength {
            get { throw new NotImplementedException(); }
        }
        public override double Width {
            get { throw new NotImplementedException(); }
        }
        public override double WidthIncludingTrailingWhitespace {
            get { throw new NotImplementedException(); }
        }

        // functions
        public override Windows.Media.TextFormatting.TextLine Collapse( params TextCollapsingProperties[] collapsingPropertiesList ) {
            throw new NotImplementedException();
        }
        public override void Draw( DrawingContext drawingContext, Windows.Point origin, InvertAxes inversion ) {
            throw new NotImplementedException();
        }
        public override CharacterHit GetBackspaceCaretCharacterHit( CharacterHit characterHit ) {
            throw new NotImplementedException();
        }

        public override CharacterHit GetCharacterHitFromDistance( double distance ) {
            throw new NotImplementedException();
        }
        public override double GetDistanceFromCharacterHit( CharacterHit characterHit ) {
            throw new NotImplementedException();
        }
        public override IEnumerable<IndexedGlyphRun> GetIndexedGlyphRuns() {
            throw new NotImplementedException();
        }
        public override CharacterHit GetNextCaretCharacterHit( CharacterHit characterHit ) {
            throw new NotImplementedException();
        }
        public override CharacterHit GetPreviousCaretCharacterHit( CharacterHit characterHit ) {
            throw new NotImplementedException();
        }
        public override IList<TextBounds> GetTextBounds( int firstTextSourceCharacterIndex, int textLength ) {
            throw new NotImplementedException();
        }
        public override IList<TextCollapsedRange> GetTextCollapsedRanges() {
            throw new NotImplementedException();
        }
        public override TextLineBreak GetTextLineBreak() {
            throw new NotImplementedException();
        }
        public override IList<TextSpan<Windows.Media.TextFormatting.TextRun>> GetTextRunSpans() {
            throw new NotImplementedException();
        }
    }

#endregion

I don't even know if that is correct, but from what it seems, none of these must override methods return anything, so what exactly does this class do ? 我什至不知道这是否正确,但是从表面上看,这些都must override任何方法,所以该类到底做什么? Does it event process any of the code such as getting a TextEffect, or is this all stuff that has to be hand written -- aka, I must make up my own TextEffects and stuff them in that code as whatever abstract structure with more methods that do nothing .... 它是否会处理任何代码,例如获取TextEffect,还是所有必须手写的东西-aka,我必须组成自己的TextEffects并将它们作为具有更多方法的抽象结构填充到该代码中没做什么 ....

You will have to derive your own class from TextParagraphProperties and override the properties as per your requirement 您将必须从TextParagraphProperties派生您自己的类,并根据需要覆盖属性

public class CustomTextParagraphProperties  : TextParagraphProperties{...}

you will also have to derive TextRunProperties and TextMarkerProperties to return your own values. 您还必须派生TextRunPropertiesTextMarkerProperties来返回您自己的值。

public class CustomTextRunProperties : TextRunProperties{...}
public class CustomTextMarkerProperties : TextMarkerProperties{...}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在这里需要参考什么? - What do I need to reference here? 创建PowerPoint演示文稿需要什么参考? - What reference do I need in order to create a PowerPoint presentation? 我需要什么才能访问自己的数据库? - What do I need to access my own Database? 我需要做什么从C#应用程序引用c ++ dll? - What do I need to do reference a c++ dll from a C# application? 如果我需要访问子类中的函数并且我有它的父引用,我该怎么办? - What can I do if I need to reach a function in child class and I have its parent reference? 尝试使用Autodesk.AutoCAD.DatabaseService从DWG读取数据,我需要引用什么DLL? - Trying to read data from a DWG using Autodesk.AutoCAD.DatabaseService What DLL do I need to reference to? 在 .NET 中使用 Microsoft.Office.Interop.Excel 需要什么参考? - What reference do I need to use Microsoft.Office.Interop.Excel in .NET? 使用NHibernate QueryOver需要什么参考? - What reference I need to use NHibernate QueryOver? 在vs2010中使用OpenGL需要添加什么参考? - What reference do I need to add to use OpenGL in vs2010? 从控制台应用程序远程连接到RDC服务器需要引用什么库? - What library do I need to reference for remote connection to RDC server from console app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM