void PDF_PLOTTER::Text( const wxPoint& aPos, enum EDA_COLOR_T aColor, const wxString& aText, double aOrient, const wxSize& aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed ) { // PDF files do not like 0 sized texts which create broken files. if( aSize.x == 0 || aSize.y == 0 ) return; // Fix me: see how to use PDF text mode for multiline texts if( aMultilineAllowed && !aText.Contains( wxT( "\n" ) ) ) aMultilineAllowed = false; // the text has only one line. // Emit native PDF text (if requested) if( m_textMode != PLOTTEXTMODE_STROKE && !aMultilineAllowed ) { const char *fontname = aItalic ? (aBold ? "/KicadFontBI" : "/KicadFontI") : (aBold ? "/KicadFontB" : "/KicadFont"); // Compute the copious tranformation parameters double ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f; double wideningFactor, heightFactor; computeTextParameters( aPos, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic, aBold, &wideningFactor, &ctm_a, &ctm_b, &ctm_c, &ctm_d, &ctm_e, &ctm_f, &heightFactor ); SetColor( aColor ); SetCurrentLineWidth( aWidth ); /* We use the full CTM instead of the text matrix because the same coordinate system will be used for the overlining. Also the %f for the trig part of the matrix to avoid %g going in exponential format (which is not supported) Rendermode 0 shows the text, rendermode 3 is invisible */ fprintf( workFile, "q %f %f %f %f %g %g cm BT %s %g Tf %d Tr %g Tz ", ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f, fontname, heightFactor, (m_textMode == PLOTTEXTMODE_NATIVE) ? 0 : 3, wideningFactor * 100 ); // The text must be escaped correctly fputsPostscriptString( workFile, aText ); fputs( " Tj ET\n", workFile ); /* We are still in text coordinates, plot the overbars (if we're * not doing phantom text) */ if( m_textMode == PLOTTEXTMODE_NATIVE ) { std::vector<int> pos_pairs; postscriptOverlinePositions( aText, aSize.x, aItalic, aBold, &pos_pairs ); int overbar_y = KiROUND( aSize.y * 1.1 ); for( unsigned i = 0; i < pos_pairs.size(); i += 2) { /* This is a nontrivial situation: we are *not* in the user coordinate system, so the userToDeviceCoordinates function can't be used! Strange as it may seem, the userToDeviceSize is the right function to use here... */ DPOINT dev_from = userToDeviceSize( wxSize( pos_pairs[i], overbar_y ) ); DPOINT dev_to = userToDeviceSize( wxSize( pos_pairs[i + 1], overbar_y ) ); fprintf( workFile, "%g %g m %g %g l ", dev_from.x, dev_from.y, dev_to.x, dev_to.y ); } } // Stroke and restore the CTM fputs( "S Q\n", workFile ); } // Plot the stroked text (if requested) if( m_textMode != PLOTTEXTMODE_NATIVE || aMultilineAllowed ) { PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic, aBold, aMultilineAllowed ); } }
void PS_PLOTTER::Text( const wxPoint& aPos, enum EDA_COLOR_T aColor, const wxString& aText, double aOrient, const wxSize& aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold ) { SetCurrentLineWidth( aWidth ); SetColor( aColor ); // Draw the native postscript text (if requested) if( m_textMode == PLOTTEXTMODE_NATIVE ) { const char *fontname = aItalic ? (aBold ? "/KicadFont-BoldOblique" : "/KicadFont-Oblique") : (aBold ? "/KicadFont-Bold" : "/KicadFont"); // Compute the copious tranformation parameters double ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f; double wideningFactor, heightFactor; computeTextParameters( aPos, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic, aBold, &wideningFactor, &ctm_a, &ctm_b, &ctm_c, &ctm_d, &ctm_e, &ctm_f, &heightFactor ); // The text must be escaped correctly, the others are the various // parameters. The CTM is formatted with %f since sin/cos tends // to make %g use exponential notation (which is not supported) fputsPostscriptString( outputFile, aText ); fprintf( outputFile, " %g [%f %f %f %f %f %f] %g %s textshow\n", wideningFactor, ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f, heightFactor, fontname ); /* The textshow operator retained the coordinate system, we use it * to plot the overbars. See the PDF sister function for more * details */ std::vector<int> pos_pairs; postscriptOverlinePositions( aText, aSize.x, aItalic, aBold, &pos_pairs ); int overbar_y = KiROUND( aSize.y * 1.1 ); for( unsigned i = 0; i < pos_pairs.size(); i += 2) { DPOINT dev_from = userToDeviceSize( wxSize( pos_pairs[i], overbar_y ) ); DPOINT dev_to = userToDeviceSize( wxSize( pos_pairs[i + 1], overbar_y ) ); fprintf( outputFile, "%g %g %g %g line ", dev_from.x, dev_from.y, dev_to.x, dev_to.y ); } // Restore the CTM fputs( "grestore\n", outputFile ); } // Draw the hidden postscript text (if requested) if( m_textMode == PLOTTEXTMODE_PHANTOM ) { fputsPostscriptString( outputFile, aText ); DPOINT pos_dev = userToDeviceCoordinates( aPos ); fprintf( outputFile, " %g %g phantomshow\n", pos_dev.x, pos_dev.y ); } // Draw the stroked text (if requested) if( m_textMode != PLOTTEXTMODE_NATIVE ) { PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic, aBold ); } }