XPs Document OriginX и единицы измерения originY - PullRequest
0 голосов
/ 27 мая 2020

У меня есть холст WPF с тремя глифами внутри. Я пытаюсь получить координаты XY для глифов в system.drawing.rectangle

Вот как выглядит страница xml для XPS

<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 в system.drawing.rectangle для windows GDI?

                    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));

                                }
...