Пример #1
0
        /// <summary>
        /// Builds the text geometry for the given string.
        /// </summary>
        /// <param name="stringToBuild">The string to build within the geometry.</param>
        /// <param name="geometryOptions">Some configuration for geometry creation.</param>
        public void BuildTextGeometry(string stringToBuild, TextGeometryOptions geometryOptions)
        {
            DWrite.Factory writeFactory = GraphicsCore.Current.FactoryDWrite;

            //TODO: Cache font objects

            //Get DirectWrite font weight
            DWrite.FontWeight fontWeight = DWrite.FontWeight.Normal;
            switch (geometryOptions.FontWeight)
            {
            case FontGeometryWeight.Bold:
                fontWeight = DWrite.FontWeight.Bold;
                break;

            default:
                fontWeight = DWrite.FontWeight.Normal;
                break;
            }

            //Get DirectWrite font style
            DWrite.FontStyle fontStyle = DWrite.FontStyle.Normal;
            switch (geometryOptions.FontStyle)
            {
            case FontGeometryStyle.Italic:
                fontStyle = DWrite.FontStyle.Italic;
                break;

            case FontGeometryStyle.Oblique:
                fontStyle = DWrite.FontStyle.Oblique;
                break;

            default:
                fontStyle = DWrite.FontStyle.Normal;
                break;
            }

            //Create the text layout object
            try
            {
                DWrite.TextLayout textLayout = new DWrite.TextLayout(
                    writeFactory, stringToBuild,
                    new DWrite.TextFormat(
                        writeFactory, geometryOptions.FontFamily, fontWeight, fontStyle, geometryOptions.FontSize),
                    float.MaxValue, float.MaxValue, 1f, true);

                //Render the text using the vertex structure text renderer
                using (VertexStructureTextRenderer textRenderer = new VertexStructureTextRenderer(this, geometryOptions))
                {
                    textLayout.Draw(textRenderer, 0f, 0f);
                }
            }
            catch (SharpDX.SharpDXException)
            {
                //TODO: Display some error
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="VertexStructureTextRenderer" /> class.
 /// </summary>
 public VertexStructureTextRenderer(VertexStructureSurface targetSurface, TextGeometryOptions textGeometryOptions)
     : base()
 {
     m_targetSurface   = targetSurface;
     m_geometryOptions = textGeometryOptions;
 }