コード例 #1
0
void wxPLDevBase::PSDrawText( PLUNICODE* ucs4, int ucs4Len, bool drawText )
{
  int i = 0;

  char utf8_string[max_string_length];
  char utf8[5];
  memset( utf8_string, '\0', max_string_length );

  /* Get PLplot escape character */
  char plplotEsc;
  plgesc( &plplotEsc );

  /* Get the curent font */
  fontScale = 1.0;
  yOffset = 0.0;
  PLUNICODE fci;
  plgfci( &fci );
  PSSetFont( fci );
  textWidth=0;
  textHeight=0;

  while( i < ucs4Len ) {
    if( ucs4[i] < PL_FCI_MARK ) {	/* not a font change */
      if( ucs4[i] != (PLUNICODE)plplotEsc ) {  /* a character to display */
        ucs4_to_utf8( ucs4[i], utf8 );
        strncat( utf8_string, utf8, max_string_length );
      	i++;
      	continue;
      }
      i++;
      if( ucs4[i] == (PLUNICODE)plplotEsc ) {   /* a escape character to display */
        ucs4_to_utf8( ucs4[i], utf8 );
        strncat( utf8_string, utf8, max_string_length );
        i++;
        continue;
      } else {
      	if( ucs4[i] == (PLUNICODE)'u' ) {	/* Superscript */
          // draw string so far
          PSDrawTextToDC( utf8_string, drawText );

          // change font scale
      		if( yOffset<0.0 )
            fontScale *= 1.25;  /* Subscript scaling parameter */
      		else
            fontScale *= 0.8;  /* Subscript scaling parameter */
          PSSetFont( fci );

      		yOffset += scaley * fontSize * fontScale / 2.;
      	}
      	if( ucs4[i] == (PLUNICODE)'d' ) {	/* Subscript */
          // draw string so far
          PSDrawTextToDC( utf8_string, drawText );

          // change font scale
          double old_fontScale=fontScale;
      		if( yOffset>0.0 )
            fontScale *= 1.25;  /* Subscript scaling parameter */
      		else
            fontScale *= 0.8;  /* Subscript scaling parameter */
          PSSetFont( fci );

      		yOffset -= scaley * fontSize * old_fontScale / 2.;
      	}
      	if( ucs4[i] == (PLUNICODE)'-' ) {	/* underline */
          // draw string so far
          PSDrawTextToDC( utf8_string, drawText );

          underlined = !underlined;
          PSSetFont( fci );
      	}
      	if( ucs4[i] == (PLUNICODE)'+' ) {	/* overline */
          /* not implemented yet */
        }
        i++;
      }
    } else { /* a font change */
      // draw string so far
      PSDrawTextToDC( utf8_string, drawText );

      // get new font
      fci = ucs4[i];
      PSSetFont( fci );
      i++;
    }
  }

  PSDrawTextToDC( utf8_string, drawText );
}
コード例 #2
0
//--------------------------------------------------------------------------
//  void wxPLDevDC::ProcessString( PLStream* pls, EscText* args )
//
//  This is the main function which processes the unicode text strings.
//  Font size, rotation and color are set, width and height of the
//  text string is determined and then the string is drawn to the canvas.
//--------------------------------------------------------------------------
void wxPLDevDC::ProcessString( PLStream* pls, EscText* args )
{
    // Check that we got unicode, warning message and return if not
    if ( args->unicode_array_len == 0 )
    {
        printf( "Non unicode string passed to the wxWidgets driver, ignoring\n" );
        return;
    }

    // Check that unicode string isn't longer then the max we allow
    if ( args->unicode_array_len >= 500 )
    {
        printf( "Sorry, the wxWidgets drivers only handles strings of length < %d\n", 500 );
        return;
    }

    // Calculate the font size (in pixels)
    fontSize = pls->chrht * VIRTUAL_PIXELS_PER_MM / scaley * 1.3;

    // Use PLplot core routine to get the corners of the clipping rectangle
    PLINT rcx[4], rcy[4];
    difilt_clip( rcx, rcy );

    wxPoint cpoints[4];
    for ( int i = 0; i < 4; i++ )
    {
        cpoints[i].x = rcx[i] / scalex;
        cpoints[i].y = height - rcy[i] / scaley;
    }
    wxDCClipper clip( *m_dc, wxRegion( 4, cpoints ) );

    // calculate rotation of text
    plRotationShear( args->xform, &rotation, &shear, &stride );
    rotation -= pls->diorot * M_PI / 2.0;
    cos_rot   = cos( rotation );
    sin_rot   = sin( rotation );

    // Set font color
    m_dc->SetTextForeground( wxColour( pls->curcolor.r, pls->curcolor.g, pls->curcolor.b ) );
    m_dc->SetTextBackground( wxColour( pls->curcolor.r, pls->curcolor.g, pls->curcolor.b ) );

    PLUNICODE *lineStart     = args->unicode_array;
    int       lineLen        = 0;
    bool      lineFeed       = false;
    bool      carriageReturn = false;
    wxCoord   paraHeight     = 0;
    // Get the curent font
    fontScale = 1.0;
    yOffset   = 0.0;
    plgfci( &fci );
    PSSetFont( fci );
    while ( lineStart != args->unicode_array + args->unicode_array_len )
    {
        while ( lineStart + lineLen != args->unicode_array + args->unicode_array_len
                && *( lineStart + lineLen ) != (PLUNICODE) '\n' )
        {
            lineLen++;
        }
        //set line feed for the beginning of this line and
        //carriage return for the end
        lineFeed       = carriageReturn;
        carriageReturn = lineStart + lineLen != args->unicode_array + args->unicode_array_len
                         && *( lineStart + lineLen ) == (PLUNICODE) ( '\n' );
        if ( lineFeed )
            paraHeight += textHeight + subscriptDepth;

        //remember the text parameters so they can be restored
        double    startingFontScale = fontScale;
        double    startingYOffset   = yOffset;
        PLUNICODE startingFci       = fci;

        // determine extent of text
        posX = args->x / scalex;
        posY = args->y / scaley;

        PSDrawText( lineStart, lineLen, false );

        if ( lineFeed && superscriptHeight > textHeight )
            paraHeight += superscriptHeight - textHeight;

        // actually draw text, resetting the font first
        fontScale = startingFontScale;
        yOffset   = startingYOffset;
        fci       = startingFci;
        PSSetFont( fci );
        posX = (PLINT) ( args->x / scalex - ( args->just * textWidth ) * cos_rot - ( 0.5 * textHeight - paraHeight * lineSpacing ) * sin_rot ); //move to set alignment
        posY = (PLINT) ( args->y / scaley - ( args->just * textWidth ) * sin_rot + ( 0.5 * textHeight - paraHeight * lineSpacing ) * cos_rot );
        PSDrawText( lineStart, lineLen, true );                                                                                                 //draw text

        lineStart += lineLen;
        if ( carriageReturn )
            lineStart++;
        lineLen = 0;
    }
    //posX = args->x;
    //posY = args->y;
    //PSDrawText( args->unicode_array, args->unicode_array_len, false );

    //posX = (PLINT) ( args->x - ( ( args->just * textWidth ) * cos_rot + ( 0.5 * textHeight ) * sin_rot ) * scalex );
    //posY = (PLINT) ( args->y - ( ( args->just * textWidth ) * sin_rot - ( 0.5 * textHeight ) * cos_rot ) * scaley );
    //PSDrawText( args->unicode_array, args->unicode_array_len, true );

    AddtoClipRegion( 0, 0, width, height );
}