c# - XPs 文档 OriginX 和 originY 单位
问题描述
我有一个 WPF 画布,里面有 3 个字形。我正在尝试获取 system.drawing.rectangle 中字形的 XY 坐标
这就是 XPS 的 pagexml 的样子
<FixedPage Width="816" Height="1056" xmlns="http://schemas.microsoft.com/xps/2005/06" xml:lang="und">
<!-- Microsoft XPS Document Converter (MXDC) Generated! Version: 0.3.17134.191 -->
<Canvas RenderTransform="1,0,0,1,32,32">
<Glyphs RenderTransform="0.044522,-0,0,0.0444336,0,0" Fill="#ff000000" FontUri="/Documents/1/Resources/Fonts/3E9F8156-D77C-47C3-8A25-0A7911D42636.odttf" FontRenderingEmSize="327.68" StyleSimulations="None" OriginX="7726.56" OriginY="1742.88" Indices="24,55;144,55;150,55;139,54;150,55;142,55;135,55;134" UnicodeString="Untitled" />
<Glyphs RenderTransform="0.044522,-0,0,0.0444336,0,0" Fill="#ff000000" FontUri="/Documents/1/Resources/Fonts/3E9F8156-D77C-47C3-8A25-0A7911D42636.odttf" FontRenderingEmSize="327.68" StyleSimulations="None" OriginX="898.4" OriginY="2128.16" Indices="22,55;23,55;18,55;19,54;3,55;19,55;4,55;28,55;16,55;8,54;17,55;23" UnicodeString="STOP PAYMENT" />
<Glyphs RenderTransform="0.044522,-0,0,0.0444336,0,0" Fill="#ff000000" FontUri="/Documents/1/Resources/Fonts/3E9F8156-D77C-47C3-8A25-0A7911D42636.odttf" FontRenderingEmSize="327.68" StyleSimulations="None" OriginX="7906.24" OriginY="20802.2" Indices="19,55;131,55;137,55;135,54;3,55;616" UnicodeString="Page 1" />
</Canvas>
</FixedPage>
如何将 originX 和 originY 转换为 windows GDI 的 system.drawing.rectangle?
FixedPage fixedPage = (FixedPage)source.Visual;
//fixedPage.Height = 1056 Height and width for fixed page come out to be 1056,816.
//fixedPage.Width = 816
Canvas MyCanvas = (Canvas)fixedPage.Children[0];
UIElementCollection canvaschildren = MyCanvas.Children;
foreach (UIElement elem in canvaschildren)
{
var glyph = (System.Windows.Documents.Glyphs)elem;
if (glyph != null)
{
double originx = Convert.ToDouble(glyph.OriginX);
double originy = Convert.ToDouble(glyph.OriginY);
// Rect bounds = VisualTreeHelper.GetDescendantBounds(elem);
Transform t = elem.RenderTransform;
if (elem.RenderTransform != null && t.Value.HasInverse)
{
double M11 = glyph.RenderTransform.Value.M11;
double M22 = glyph.RenderTransform.Value.M22;
double canvasXoffset = 0;
double canvasYoffset = 0; ;
var canvasOffsert = MyCanvas.RenderTransform;
if (canvasOffsert != null)
{
canvasXoffset = canvasOffsert.Value.OffsetX;
canvasYoffset = canvasOffsert.Value.OffsetY;
}
originx *= M11;
originy *= M22;
originx -= canvasXoffset;
originy -= canvasYoffset;
int pixelx, pixely;
//??? Convert the originX and OriginY to XY location in GDI. I tried a bunch of stuff and nothing gets me the numbers I want.
text = text.Append(string.Format("<{0}{1}>{2}", p1.Y.ToString().PadLeft(4, '0'), p1.X.ToString().PadLeft(4, '0'), glyph.UnicodeString));
}
解决方案
推荐阅读
- flutter - 如何将指定的图像资产添加到 pubspec,然后将图像加载到 AssetImage 以供应用程序呈现?
- lua - lua 5.1中的uint64到十六进制
- android - Android:在 TextView 中将肤色应用于表情符号
- ruby-on-rails - 如何从 ruby on rails 中的 csv 文件中读取 csv 文件数据
- c# - 我正在从 gridview 中删除行,但表中的所有数据都已删除
- javascript - 如何将下一个和上一个按钮添加到我的反应幻灯片网站
- android - 上次更新 android studio 中的数据绑定
- sql - Snowflake:SQL Query 用于从同一个或多个表中识别具有相同 ID 的所有不同用户
- python - 打印可被 3 或 5 整除的数字的计数
- c++ - 派生类是否为继承的变量分配内存,或者它只是访问它?