Logo Search packages:      
Sourcecode: codeblocks version File versions  Download package

void wxPdfDocument::ShapedText ( const wxPdfShape shape,
const wxString &  text,
wxPdfShapedTextMode  mode = wxPDF_SHAPEDTEXTMODE_STRETCHTOFIT 
)

Prints a text string along a path defined by a shape.

Parameters:
shapeshape defining a path along which the text is printed
texttext string to be printed
modeflag how to handle the text string

  • wxPDF_SHAPEDTEXTMODE_ONETIME: the text should be printed at most one time depending on the path length
  • wxPDF_SHAPEDTEXTMODE_STRETCHTOFIT: the text should be stretched to fit exactly along the given path (default)
  • wxPDF_SHAPEDTEXTMODE_REPEAT: the text should be repeated if the text length is shorter than the path length

Definition at line 786 of file pdfgraphics.cpp.

References wxPdfFlatPath::CurrentSegment(), GetFontSize(), GetScaleFactor(), GetStringWidth(), wxPdfFlatPath::IsDone(), wxPdfFlatPath::MeasurePathLength(), wxPdfFlatPath::Next(), Rotate(), SetXY(), StartTransform(), StopTransform(), and Write().

{
  bool stretchToFit = (mode == wxPDF_SHAPEDTEXTMODE_STRETCHTOFIT);
  bool repeat = (mode == wxPDF_SHAPEDTEXTMODE_REPEAT);
  double flatness = 0.25 / GetScaleFactor();
  wxPdfFlatPath it(&shape, flatness);
  double points[6];
  double moveX = 0, moveY = 0;
  double lastX = 0, lastY = 0;
  double thisX = 0, thisY = 0;
  int type = 0;
  bool first = false;
  double next = 0;
  int currentChar = 0;
  int length = text.Length();
  double height = GetFontSize() / GetScaleFactor();

  if ( length == 0 )
    return;

  double factor = stretchToFit ? it.MeasurePathLength() / GetStringWidth(text) : 1.0;
  double nextAdvance = 0;

  while (currentChar < length && !it.IsDone())
  {
    type = it.CurrentSegment(points);
    switch (type)
    {
      case wxPDF_SEG_MOVETO:
        moveX = lastX = points[0];
        moveY = lastY = points[1];
        SetXY(moveX, moveY);
        first = true;
        nextAdvance = GetStringWidth(text.Mid(currentChar,1)) * 0.5;
        next = nextAdvance;
        break;

      case wxPDF_SEG_CLOSE:
        points[0] = moveX;
        points[1] = moveY;
        // Fall into....

      case wxPDF_SEG_LINETO:
        thisX = points[0];
        thisY = points[1];
        double dx = thisX-lastX;
        double dy = thisY-lastY;
        double distance = sqrt(dx*dx + dy*dy);
        if (distance >= next)
        {
          double r = 1.0 / distance;
          double angle = atan2(-dy, dx) * 45. / atan(1.);
          while (currentChar < length && distance >= next)
          {
            wxString glyph = text.Mid(currentChar, 1);
            double x = lastX + next*dx*r;
            double y = lastY + next*dy*r;
            double advance = nextAdvance;
            nextAdvance = currentChar < length-1 ? GetStringWidth(text.Mid(currentChar+1,1)) * 0.5 :
                                                   (repeat) ? GetStringWidth(text.Mid(0,1)) * 0.5 : 0;
            SetXY(x, y);
            StartTransform();
            Rotate(angle);
            SetXY(x-advance,y-height);
            Write(height, glyph);
            StopTransform();
            next += (advance+nextAdvance) * factor;
            currentChar++;
            if ( repeat )
            {
              currentChar %= length;
            }
          }
        }
        next -= distance;
        first = false;
        lastX = thisX;
        lastY = thisY;
        break;
    }
    it.Next();
  }
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index