0

I am rendering XPS using WPF. This is completely dynamic (XAML free).

In my code, I have following code to set up text rotation.

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

It is inside FlowPanel, therefore some bug is preventing me from setting rotation for whole paragraph (more on that here http://social.msdn.microsoft.com/Forums/nl/wpf/thread/931f1995-d039-4364-b09b-fcd0a43fd737)

My problem is, even when I use the fix, result is not correct. After certain amount of characters, text is not rotated anymore:

enter image description here

Note, that screenshot is from XPS to which I render result. When I render it to XAML, you can see that effect is correctly mapped to all Runs in text.

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

Now, does anyone has any idea how to achieve rotation for whole text as I really need it.

Thanks

EDIT: For quick test that it does not work properly, you can create WPF application and just paste following XAML Code

<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>
Ales Ruzicka
  • 2,770
  • 1
  • 18
  • 24

1 Answers1

0

So, I've fixed it by switching

effect.PositionCount = 100

to

effect.PositionCount = Integer.Max

which fixed the problem.

I did not understand correctly what it stood for and thought it means something like percentage of effect done.

Ales Ruzicka
  • 2,770
  • 1
  • 18
  • 24