silverlight   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了将普通文字转成路径(Path)的方法 (WPF,Silverlight,SVG)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

在WPF中使用 public String GetTextPath(String word, String fontFamily, int fontSizE) { Typeface typeface = new Typeface(new FontFamily(fontFamily), FontStyles.Normal, FontWeights.Normal, FontSt

在WPF中使用

public String GetTextPath(String word,String fontFamily,int fontSizE)
{
            Typeface typeface = new Typeface(new FontFamily(fontFamily),FontStyles.Normal,FontWeights.Normal,FontStretches.Normal); 
            return GetTextPath(word,typeface,fontSizE);
}
public String GetTextPath(String word,Typeface typeface,int fontSizE)
{
            Formatted@R_566_3801@ = new FormattedText(word,new System.Globalization.CultureInfo("zh-cn"),FlowDirection.LeftToRight,fontSize,Brushes.black);
            Geometry geo = text.buildGeometry(new Point(0,0)); 
            PathGeometry path = geo.GetFlattenedPathGeometry();
            return path.ToString(); 
}@H_944_26@ 


用法
<Path x:Name="textPath" Canvas.Left="10" Canvas.Top="10" Fill="#FFFF0000" />


C#代码
rootElement.findName('textPath').Data = GetTextPath("测试一下A Test!","方正大黑简体",42);



在SVG/Silverlight中使用,可以写成 WCF

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.serialization;
using System.serviceModel;
using System.serviceModel.Web;
using System.Text;

// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码配置文件中的接口名“Iservice”。
[serviceContract]
public interface Iservice
{
    [OperationContract]
    String GetTextPath(FontParam cs);
}


[DataContract]
public class FontParam
{
    String word = "";
    String fontFamily = "宋体";
    int fontSize = 12;

    [DataMember]
    public String Word
    {
        get { return word; }
        set { word = value; }
    }

    [DataMember]
    public String FontFamily
    {
        get { return fontFamily; }
        set { fontFamily = value; }
    }

    [DataMember]
    public int FontSize
    {
        get { return fontSize; }
        set { fontSize = value; }
    }
}
@H_944_26@ 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.serialization;
using System.serviceModel;
using System.serviceModel.Web;
using System.Text;

using System.Windows.Media;
using System.Windows;

// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、服务和配置文件中的类名“service”。
public class service : Iservice
{
    public String GetTextPath(FontParam fp)
    {
        Typeface typeface = new Typeface(new FontFamily(fp.FontFamily),FontStretches.Normal);
        return GetTextPath(fp.Word,fp.FontSizE);
    }

    private String GetTextPath(String word,int fontSizE)
    {
        Formatted@R_566_3801@ = new FormattedText(word,Brushes.black);

        Geometry geo = text.buildGeometry(new System.Windows.Point(0,0));
        PathGeometry path = geo.GetFlattenedPathGeometry();

        return path.ToString();
    }
}
@H_944_26@ 

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="PresentationCore,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="WindowsBase,PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息-->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHosTingEnvironment multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllrequests="true"/>
  </system.webServer>
</configuration>@H_944_26@ 

记得添加PresentationCore.dll和WindowsBase.dll的引用,这两个在.net 4.0 /wpf 的目录下


 serviceReference1.serviceClient sc = new serviceReference1.serviceClient();
            serviceReference1.FontParam cs = new serviceReference1.Font@R_970_1403@;
            cs.FontSize = fontSize.AsInt();
            cs.FontFamily = fontFamily;
            cs.Word = word;
            haha = sc.GetTextPath(cs);@H_944_26@ 

哈哈,这样就可以了!!



来自(http://www.voidcn.com/article/p-rdtkyzub-yk.html

大佬总结

以上是大佬教程为你收集整理的将普通文字转成路径(Path)的方法 (WPF,Silverlight,SVG)全部内容,希望文章能够帮你解决将普通文字转成路径(Path)的方法 (WPF,Silverlight,SVG)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。