单行文字压缩处理(要指定字体)
代码
/// <summary>
/// 单行文字压缩处理
/// </summary>
/// <param name="txt">单行文字</param>
/// <param name="dL">需要压到的长度</param>
public static void RarDBText(Database db, DBText txt, double dL)
{
if (txt.TextString.Equals("")) return;
txt.TextStyle = db.Textstyle; //因为不同的字体它的范围不同,如果没有此句,将默认为gbig字体,将出现偏差
double ange = txt.Rotation;
TextHorizontalMode horM = txt.HorizontalMode;
txt.Rotation = 0;
txt.HorizontalMode = TextHorizontalMode.TextLeft;
double xL = txt.GeometricExtents.MaxPoint.X - txt.Position.X;
if (xL > dL)
{
txt.WidthFactor = txt.WidthFactor * (dL / xL);
}
//还原
txt.Rotation = ange;
txt.HorizontalMode = horM;
}
/// 单行文字压缩处理
/// </summary>
/// <param name="txt">单行文字</param>
/// <param name="dL">需要压到的长度</param>
public static void RarDBText(Database db, DBText txt, double dL)
{
if (txt.TextString.Equals("")) return;
txt.TextStyle = db.Textstyle; //因为不同的字体它的范围不同,如果没有此句,将默认为gbig字体,将出现偏差
double ange = txt.Rotation;
TextHorizontalMode horM = txt.HorizontalMode;
txt.Rotation = 0;
txt.HorizontalMode = TextHorizontalMode.TextLeft;
double xL = txt.GeometricExtents.MaxPoint.X - txt.Position.X;
if (xL > dL)
{
txt.WidthFactor = txt.WidthFactor * (dL / xL);
}
//还原
txt.Rotation = ange;
txt.HorizontalMode = horM;
}