Make texts search-able in PDF files (using invisible texts behind stroked texts)
This commit is contained in:
parent
9447181a08
commit
0999b5cb77
|
@ -775,18 +775,22 @@ void PDF_PLOTTER::Text( const wxPoint& aPos,
|
||||||
aMultilineAllowed = false; // the text has only one line.
|
aMultilineAllowed = false; // the text has only one line.
|
||||||
|
|
||||||
// Emit native PDF text (if requested)
|
// Emit native PDF text (if requested)
|
||||||
// Currently: does not work: disable it
|
// Currently: is not supported, because only our stroke font is alloxed: disable it
|
||||||
bool use_native = false; // = m_textMode != PLOTTEXTMODE_STROKE && !aMultilineAllowed;
|
// However, shadowed texts (searchable texts) works reasonably well because
|
||||||
|
// pixel accurate precision is not requested, so we add searchable texts
|
||||||
|
// behind our stroked font texts
|
||||||
|
bool use_native_font = false;
|
||||||
|
// render_mode 0 shows the text, render_mode 3 is invisible
|
||||||
|
int render_mode = use_native_font ? 0 : 3;
|
||||||
|
|
||||||
if( use_native )
|
|
||||||
{
|
|
||||||
const char *fontname = aItalic ? (aBold ? "/KicadFontBI" : "/KicadFontI")
|
const char *fontname = aItalic ? (aBold ? "/KicadFontBI" : "/KicadFontI")
|
||||||
: (aBold ? "/KicadFontB" : "/KicadFont");
|
: (aBold ? "/KicadFontB" : "/KicadFont");
|
||||||
|
|
||||||
// Compute the copious tranformation parameters
|
// Compute the copious tranformation parameters of the Curent Transform Matrix
|
||||||
double ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f;
|
double ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f;
|
||||||
double wideningFactor, heightFactor;
|
double wideningFactor, heightFactor;
|
||||||
computeTextParameters( aPos, aText, aOrient, aSize, aH_justify,
|
|
||||||
|
computeTextParameters( aPos, aText, aOrient, aSize, m_plotMirror, aH_justify,
|
||||||
aV_justify, aWidth, aItalic, aBold,
|
aV_justify, aWidth, aItalic, aBold,
|
||||||
&wideningFactor, &ctm_a, &ctm_b, &ctm_c,
|
&wideningFactor, &ctm_a, &ctm_b, &ctm_c,
|
||||||
&ctm_d, &ctm_e, &ctm_f, &heightFactor );
|
&ctm_d, &ctm_e, &ctm_f, &heightFactor );
|
||||||
|
@ -798,20 +802,18 @@ void PDF_PLOTTER::Text( const wxPoint& aPos,
|
||||||
coordinate system will be used for the overlining. Also the %f
|
coordinate system will be used for the overlining. Also the %f
|
||||||
for the trig part of the matrix to avoid %g going in exponential
|
for the trig part of the matrix to avoid %g going in exponential
|
||||||
format (which is not supported)
|
format (which is not supported)
|
||||||
Rendermode 0 shows the text, rendermode 3 is invisible */
|
render_mode 0 shows the text, render_mode 3 is invisible */
|
||||||
fprintf( workFile, "q %f %f %f %f %g %g cm BT %s %g Tf %d Tr %g Tz ",
|
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,
|
ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f,
|
||||||
fontname, heightFactor,
|
fontname, heightFactor, render_mode,
|
||||||
(m_textMode == PLOTTEXTMODE_NATIVE) ? 0 : 3,
|
|
||||||
wideningFactor * 100 );
|
wideningFactor * 100 );
|
||||||
|
|
||||||
// The text must be escaped correctly
|
// The text must be escaped correctly
|
||||||
fputsPostscriptString( workFile, aText );
|
fputsPostscriptString( workFile, aText );
|
||||||
fputs( " Tj ET\n", workFile );
|
fputs( " Tj ET\n", workFile );
|
||||||
|
|
||||||
/* We are still in text coordinates, plot the overbars (if we're
|
// We are in text coordinates, plot the overbars, if we're not doing phantom text
|
||||||
* not doing phantom text) */
|
if( use_native_font )
|
||||||
if( m_textMode == PLOTTEXTMODE_NATIVE )
|
|
||||||
{
|
{
|
||||||
std::vector<int> pos_pairs;
|
std::vector<int> pos_pairs;
|
||||||
postscriptOverlinePositions( aText, aSize.x, aItalic, aBold, &pos_pairs );
|
postscriptOverlinePositions( aText, aSize.x, aItalic, aBold, &pos_pairs );
|
||||||
|
@ -831,10 +833,9 @@ void PDF_PLOTTER::Text( const wxPoint& aPos,
|
||||||
|
|
||||||
// Stroke and restore the CTM
|
// Stroke and restore the CTM
|
||||||
fputs( "S Q\n", workFile );
|
fputs( "S Q\n", workFile );
|
||||||
}
|
|
||||||
|
|
||||||
// Plot the stroked text (if requested)
|
// Plot the stroked text (if requested)
|
||||||
if( !use_native )
|
if( !use_native_font )
|
||||||
{
|
{
|
||||||
PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify,
|
PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify,
|
||||||
aWidth, aItalic, aBold, aMultilineAllowed );
|
aWidth, aItalic, aBold, aMultilineAllowed );
|
||||||
|
|
|
@ -427,6 +427,7 @@ void PSLIKE_PLOTTER::computeTextParameters( const wxPoint& aPos,
|
||||||
const wxString& aText,
|
const wxString& aText,
|
||||||
int aOrient,
|
int aOrient,
|
||||||
const wxSize& aSize,
|
const wxSize& aSize,
|
||||||
|
bool aMirror,
|
||||||
enum EDA_TEXT_HJUSTIFY_T aH_justify,
|
enum EDA_TEXT_HJUSTIFY_T aH_justify,
|
||||||
enum EDA_TEXT_VJUSTIFY_T aV_justify,
|
enum EDA_TEXT_VJUSTIFY_T aV_justify,
|
||||||
int aWidth,
|
int aWidth,
|
||||||
|
@ -487,7 +488,14 @@ void PSLIKE_PLOTTER::computeTextParameters( const wxPoint& aPos,
|
||||||
DPOINT sz_dev = userToDeviceSize( aSize );
|
DPOINT sz_dev = userToDeviceSize( aSize );
|
||||||
|
|
||||||
// Now returns the final values... the widening factor
|
// Now returns the final values... the widening factor
|
||||||
*wideningFactor = sz_dev.y / sz_dev.x;
|
*wideningFactor = sz_dev.x / sz_dev.y;
|
||||||
|
|
||||||
|
// Mirrored texts must be plotted as mirrored!
|
||||||
|
if( m_plotMirror )
|
||||||
|
{
|
||||||
|
*wideningFactor = -*wideningFactor;
|
||||||
|
aOrient = -aOrient;
|
||||||
|
}
|
||||||
|
|
||||||
// The CTM transformation matrix
|
// The CTM transformation matrix
|
||||||
double alpha = DECIDEG2RAD( aOrient );
|
double alpha = DECIDEG2RAD( aOrient );
|
||||||
|
@ -953,7 +961,7 @@ void PS_PLOTTER::Text( const wxPoint& aPos,
|
||||||
// Compute the copious tranformation parameters
|
// Compute the copious tranformation parameters
|
||||||
double ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f;
|
double ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f;
|
||||||
double wideningFactor, heightFactor;
|
double wideningFactor, heightFactor;
|
||||||
computeTextParameters( aPos, aText, aOrient, aSize, aH_justify,
|
computeTextParameters( aPos, aText, aOrient, aSize, m_plotMirror, aH_justify,
|
||||||
aV_justify, aWidth, aItalic, aBold,
|
aV_justify, aWidth, aItalic, aBold,
|
||||||
&wideningFactor, &ctm_a, &ctm_b, &ctm_c,
|
&wideningFactor, &ctm_a, &ctm_b, &ctm_c,
|
||||||
&ctm_d, &ctm_e, &ctm_f, &heightFactor );
|
&ctm_d, &ctm_e, &ctm_f, &heightFactor );
|
||||||
|
|
|
@ -692,6 +692,7 @@ protected:
|
||||||
const wxString& aText,
|
const wxString& aText,
|
||||||
int aOrient,
|
int aOrient,
|
||||||
const wxSize& aSize,
|
const wxSize& aSize,
|
||||||
|
bool aMirror,
|
||||||
enum EDA_TEXT_HJUSTIFY_T aH_justify,
|
enum EDA_TEXT_HJUSTIFY_T aH_justify,
|
||||||
enum EDA_TEXT_VJUSTIFY_T aV_justify,
|
enum EDA_TEXT_VJUSTIFY_T aV_justify,
|
||||||
int aWidth,
|
int aWidth,
|
||||||
|
|
Loading…
Reference in New Issue