问题
I am trying to print a Canvas that contains a glyph element using Silverlight 5's vector printing capacity. Everything works fine except that glyphs do not get printed. Are glyphs supported by vector printing? If so, what am I doing wrong? I am trying to print the following canvas that shows up correctly on the screen:
<Canvas x:Name="canvasToPrint" Margin="-96,-34,0,0" Grid.ColumnSpan="2" Background="AliceBlue">
<Rectangle Fill="Blue" Width="39" Height="36"/>
<Glyphs Name="a0" Fill="#FF000000" FontUri="36481AB7-37EB-642E-4A01-FB63CC6ED952.odttf" FontRenderingEmSize="11.04" StyleSimulations="None" OriginX="72.024" OriginY="82.464" UnicodeString="Hello, World!" Indices=",61.957;,50;,22.826;,22.826;,53.261;,25;,21.739;,89.13;,53.261;,34.783;,22.826;,52.174;">
</Glyphs>
<Button Height="25" Content="Print" Click="Button_Click"/>
</Canvas>
With the following code for a print button:
private void Button_Click(object sender, RoutedEventArgs e)
{
PrintDocument doc = new PrintDocument();
doc.BeginPrint += new EventHandler<BeginPrintEventArgs>(BeginPrinting);
doc.PrintPage += new EventHandler<PrintPageEventArgs>(PrintNextPage);
doc.Print("vector");
}
private void BeginPrinting(Object sender, BeginPrintEventArgs e)
{
}
private void PrintNextPage(Object sender, PrintPageEventArgs e)
{
e.PageVisual = canvasToPrint;
e.HasMorePages = false;
}
Note that everything prints correctly if I switch doc.Print
to doc.PrintBitmap
.
来源:https://stackoverflow.com/questions/9012014/vector-printing-glyphs-in-silverlight-5