我正在使用 WPF 渲染 XPS。这是完全动态的(XAML 免费)。
在我的代码中,我有以下代码来设置文本旋转。
Private Shared Sub ApplyRotation(style As BoxStyleData, run As TextElement)
If style IsNot Nothing Then
If Math.Abs(style.TextRotation) > Double.Epsilon Then
Dim effects = New TextEffectCollection
Dim effect = New TextEffect()
effect.Transform = New RotateTransform(style.TextRotation)
effect.PositionCount = 100
effects.Add(effect)
run.TextEffects = effects
End If
End If
End Sub
它在 FlowPanel 内,因此一些错误阻止我为整个段落设置旋转(更多关于这里http://social.msdn.microsoft.com/Forums/nl/wpf/thread/931f1995-d039-4364-b09b- fcd0a43fd737 )
我的问题是,即使我使用修复程序,结果也不正确。在一定数量的字符之后,文本不再旋转:
请注意,该屏幕截图来自我渲染结果的 XPS。当我将它呈现到 XAML 时,您可以看到效果已正确映射到文本中的所有Runs
内容。
<Paragraph Margin="0,0,0,0" Padding="0,18.9,0,0" TextAlignment="Center" ClearFloaters="None" FontSize="14.62">
<Span FontSize="14.62"><Run><Run.TextEffects><TextEffect PositionCount="100"><TextEffect.Transform><RotateTransform Angle="356.7" /></TextEffect.Transform></TextEffect></Run.TextEffects>Denken Sie frühzeitig</Run></Span><LineBreak />
<Span FontSize="14.62"><Run><Run.TextEffects><TextEffect PositionCount="100"><TextEffect.Transform><RotateTransform Angle="356.7" /></TextEffect.Transform></TextEffect></Run.TextEffects>an den</Run></Span><LineBreak />
<Span FontSize="14.62"><Run><Run.TextEffects><TextEffect PositionCount="100"><TextEffect.Transform><RotateTransform Angle="356.7" /></TextEffect.Transform></TextEffect></Run.TextEffects>Räderwechsel!</Run></Span><LineBreak />
<LineBreak />
<Span FontSize="14.62"><Run><Run.TextEffects><TextEffect PositionCount="100"><TextEffect.Transform><RotateTransform Angle="356.7" /></TextEffect.Transform></TextEffect></Run.TextEffects>Unser</Run></Span><LineBreak />
<Span FontWeight="Bold" FontSize="14.62"><Run><Run.TextEffects><TextEffect PositionCount="100"><TextEffect.Transform><RotateTransform Angle="356.7" /></TextEffect.Transform></TextEffect></Run.TextEffects>Winter Check-Point</Run></Span><LineBreak />
<Span FontSize="14.62"><Run><Run.TextEffects><TextEffect PositionCount="100"><TextEffect.Transform><RotateTransform Angle="356.7" /></TextEffect.Transform></TextEffect></Run.TextEffects>ist für Sie offen!</Run></Span></Paragraph>
现在,有没有人知道如何实现整个文本的旋转,因为我真的需要它。
谢谢
编辑:为了快速测试它不能正常工作,您可以创建 WPF 应用程序并粘贴以下 XAML 代码
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<FlowDocumentPageViewer>
<FlowDocument>
<Paragraph Margin="0,0,0,0" Padding="0,18.9,0,0" TextAlignment="Center" ClearFloaters="None" FontSize="14.62">
<Span FontSize="14.62">
<Run>
<Run.TextEffects>
<TextEffect PositionCount="100">
<TextEffect.Transform>
<RotateTransform Angle="356.7" />
</TextEffect.Transform>
</TextEffect>
</Run.TextEffects> Denken Sie frühzeiti
</Run>
</Span>
<LineBreak />
<Span FontSize="14.62">
<Run>
<Run.TextEffects>
<TextEffect PositionCount="100">
<TextEffect.Transform>
<RotateTransform Angle="356.7" />
</TextEffect.Transform>
</TextEffect>
</Run.TextEffects> an den
</Run>
</Span>
<LineBreak />
<Span FontSize="14.62">
<Run>
<Run.TextEffects>
<TextEffect PositionCount="100">
<TextEffect.Transform>
<RotateTransform Angle="356.7" />
</TextEffect.Transform>
</TextEffect>
</Run.TextEffects> Räderwechsel!
</Run>
</Span>
<LineBreak />
<LineBreak />
<Span FontSize="14.62">
<Run>
<Run.TextEffects>
<TextEffect PositionCount="100">
<TextEffect.Transform>
<RotateTransform Angle="356.7" />
</TextEffect.Transform>
</TextEffect>
</Run.TextEffects> Unser
</Run>
</Span>
<LineBreak />
<Span FontWeight="Bold" FontSize="14.62">
<Run>
<Run.TextEffects>
<TextEffect PositionCount="100">
<TextEffect.Transform>
<RotateTransform Angle="356.7" />
</TextEffect.Transform>
</TextEffect>
</Run.TextEffects> Winter Check-Point
</Run>
</Span>
<LineBreak />
<Span FontSize="14.62">
<Run>
<Run.TextEffects>
<TextEffect PositionCount="100">
<TextEffect.Transform>
<RotateTransform Angle="356.7" />
</TextEffect.Transform>
</TextEffect>
</Run.TextEffects> ist für Sie offen!
</Run>
</Span>
</Paragraph>
</FlowDocument>
</FlowDocumentPageViewer>
</Grid>
</Window>