+static int
+paps_cubic_to( FT_Vector* control1, FT_Vector* control2,
+ FT_Vector* to, void *user_data)
+{
+ OutlineInfo *outline_info = (OutlineInfo*)user_data;
+ outline_info->caller->PsPrintf(wxT("%d %d %d %d %d %d curveto\n"),
+ (int)control1->x ,
+ (int)control1->y ,
+ (int)control2->x ,
+ (int)control2->y ,
+ (int)to->x ,
+ (int)to->y );
+ return 0;
+}
+
+void draw_bezier_outline(wxPostScriptDC* caller,
+ FT_Face face,
+ FT_UInt glyph_index,
+ int pos_x,
+ int pos_y,
+ double scale_x,
+ double scale_y )
+{
+ FT_Int load_flags = FT_LOAD_NO_BITMAP;
+ FT_Glyph glyph;
+
+ FT_Outline_Funcs outlinefunc =
+ {
+ paps_move_to,
+ paps_line_to,
+ paps_conic_to,
+ paps_cubic_to
+ };
+
+ OutlineInfo outline_info;
+ outline_info.caller = caller;
+
+ caller->PsPrint("gsave\n");
+ caller->PsPrintf( wxT("%d %d translate\n"), pos_x, pos_y );
+
+ // We have to replace the "," from the German
+ // locale with the Englich "." for PostScript
+ char buf[100];
+ sprintf(buf, "%.8f %.8f scale\n", scale_x, scale_y );
+ for (size_t i = 0; i < strlen(buf); i++)
+ if (buf[i] == ',') buf[i] = '.';
+ caller->PsPrint(buf);
+
+ FT_Load_Glyph(face, glyph_index, load_flags);
+ FT_Get_Glyph (face->glyph, &glyph);
+ FT_Outline_Decompose (&(((FT_OutlineGlyph)glyph)->outline),
+ &outlinefunc, &outline_info);
+ caller->PsPrint("closepath fill grestore\n");
+
+ FT_Done_Glyph (glyph);
+}
+
+#endif
+
+void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
+{
+ wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
+
+ if (m_textForegroundColour.Ok())
+ {
+ unsigned char red = m_textForegroundColour.Red();
+ unsigned char blue = m_textForegroundColour.Blue();
+ unsigned char green = m_textForegroundColour.Green();
+
+ if (!m_colour)
+ {
+ // Anything not white is black
+ if (! (red == (unsigned char) 255 &&
+ blue == (unsigned char) 255 &&
+ green == (unsigned char) 255))
+ {
+ red = (unsigned char) 0;
+ green = (unsigned char) 0;
+ blue = (unsigned char) 0;
+ }
+ }
+
+ // maybe setgray here ?
+ if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
+ {
+ double redPS = (double)(red) / 255.0;
+ double bluePS = (double)(blue) / 255.0;
+ double greenPS = (double)(green) / 255.0;
+
+ char buffer[100];
+ sprintf( buffer,
+ "%.8f %.8f %.8f setrgbcolor\n",
+ redPS, greenPS, bluePS );
+ for (size_t i = 0; i < strlen(buffer); i++)
+ if (buffer[i] == ',') buffer[i] = '.';
+ PsPrint( buffer );
+
+ m_currentRed = red;
+ m_currentBlue = blue;
+ m_currentGreen = green;
+ }
+ }
+
+#if wxUSE_PANGO
+ int ps_dpi = 72;
+ int pango_dpi = 600;
+ PangoContext *context = pango_ft2_get_context ( pango_dpi, pango_dpi );
+
+ double scale = (double)pango_dpi / (double)ps_dpi;
+ scale /= m_userScaleY;
+
+ pango_context_set_language (context, pango_language_from_string ("en_US"));
+ pango_context_set_base_dir (context, PANGO_DIRECTION_LTR );
+
+ pango_context_set_font_description (context, m_font.GetNativeFontInfo()->description );
+
+ PangoLayout *layout = pango_layout_new (context);
+#if wxUSE_UNICODE
+ wxCharBuffer buffer = wxConvUTF8.cWC2MB( text );
+#else
+ wxCharBuffer buffer = wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) );
+#endif
+ pango_layout_set_text( layout, (const char*) buffer, strlen(buffer) );
+
+ PsPrintf( wxT("%%%% %s\n"), text.c_str() );
+
+ PangoRectangle rect;
+ pango_layout_get_extents(layout, NULL, &rect);
+
+ int xx = LogicalToDeviceX( x );
+ int yy = LogicalToDeviceY( y );
+
+ int xxx = xx * PANGO_SCALE;
+ int yyy = yy * PANGO_SCALE - (int)(rect.height * 0.66 / scale); // Move down by estimated baseline. HACK.
+
+#define ps_kludge_factor 2.8
+
+ // Loop over lines in layout
+ int num_lines = pango_layout_get_line_count( layout );
+ for (int i = 0; i < num_lines; i++)
+ {
+ PangoLayoutLine *line = pango_layout_get_line( layout, i );
+
+ // width of glyphs already printed
+ int all_width = 0;
+
+ // Loop over runs in line
+ GSList *runs_list = line->runs;
+ while (runs_list)
+ {
+ PangoLayoutRun *run = (PangoLayoutRun*) runs_list->data;
+ PangoItem *item = run->item;
+ PangoGlyphString *glyphs = run->glyphs;
+ PangoAnalysis *analysis = &item->analysis;
+ PangoFont *font = analysis->font;
+ FT_Face ft_face = pango_ft2_font_get_face(font);
+
+ int num_glyphs = glyphs->num_glyphs;
+ for (int glyph_idx = 0; glyph_idx < num_glyphs; glyph_idx++)
+ {
+ PangoGlyphGeometry geometry = glyphs->glyphs[glyph_idx].geometry;
+ int pos_x = xxx + (int)((double)(all_width+geometry.x_offset) / scale);
+ int pos_y = yyy + (int)((double)geometry.y_offset / scale );
+ all_width += geometry.width;
+
+ draw_bezier_outline( this, ft_face,
+ (FT_UInt)(glyphs->glyphs[glyph_idx].glyph),
+ pos_x / PANGO_SCALE,
+ pos_y / PANGO_SCALE,
+ 1.0/(ps_kludge_factor * scale * 26.6),
+ 1.0/(ps_kludge_factor * scale * 26.6) );
+ }
+ runs_list = runs_list->next;
+ }
+ }
+
+ g_object_unref( G_OBJECT( layout ) );
+ g_object_unref( G_OBJECT( context ) );
+#else // !wxUSE_PANGO
+ wxCoord text_w, text_h, text_descent;
+
+ GetTextExtent(text, &text_w, &text_h, &text_descent);
+
+ // VZ: this seems to be unnecessary, so taking it out for now, if it
+ // doesn't create any problems, remove this comment entirely
+ //SetFont( m_font );
+
+
+ int size = m_font.GetPointSize();
+
+// wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
+// commented by V. Slavik and replaced by accurate version
+// - note that there is still rounding error in text_descent!
+ wxCoord by = y + size - text_descent; // baseline
+
+ PsPrintf( wxT("%d %d moveto\n"), LogicalToDeviceX(x), LogicalToDeviceY(by) );
+ PsPrint( "(" );
+
+ const wxWX2MBbuf textbuf = text.mb_str();
+ size_t len = strlen(textbuf);
+ size_t i;
+ for (i = 0; i < len; i++)
+ {
+ int c = (unsigned char) textbuf[i];
+ if (c == ')' || c == '(' || c == '\\')
+ {
+ /* Cope with special characters */
+ PsPrint( "\\" );
+ PsPrint(c);
+ }
+ else if ( c >= 128 )
+ {
+ /* Cope with character codes > 127 */
+ PsPrintf( wxT("\\%o"), c);
+ }
+ else
+ {
+ PsPrint(c);
+ }
+ }
+
+ PsPrint( ") show\n" );
+