#include "wx/log.h"
#include "wx/generic/dcpsg.h"
#include "wx/prntbase.h"
+#include "wx/generic/prntdlgg.h"
#include "wx/paper.h"
#include "wx/filefn.h"
#if WXWIN_COMPATIBILITY_2_2
m_pageNumber = 0;
- m_clipping = FALSE;
+ m_clipping = false;
m_underlinePosition = 0.0;
m_underlineThickness = 0.0;
m_pageNumber = 0;
- m_clipping = FALSE;
+ m_clipping = false;
m_underlinePosition = 0.0;
m_underlineThickness = 0.0;
m_printData = printData;
- m_ok = TRUE;
+ m_ok = true;
}
wxPostScriptDC::~wxPostScriptDC ()
{
wxPrintDialogData ddata( data );
wxPrintDialog dialog( parent, &data );
- dialog.GetPrintDialogData().SetSetupDialog(TRUE);
+ dialog.GetPrintDialogData().SetSetupDialog(true);
if (dialog.ShowModal() != wxID_OK)
{
- m_ok = FALSE;
- return FALSE;
+ m_ok = false;
+ return false;
}
data = dialog.GetPrintDialogData().GetPrintData();
}
- return TRUE;
+ return true;
}
#endif
wxDC::DoSetClippingRegion(x, y, w, h);
- m_clipping = TRUE;
+ m_clipping = true;
PsPrintf( wxT("gsave\n newpath\n")
wxT("%d %d moveto\n")
if (m_clipping)
{
- m_clipping = FALSE;
+ m_clipping = false;
PsPrint( "grestore\n" );
}
bool wxPostScriptDC::DoFloodFill (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxColour &WXUNUSED(col), int WXUNUSED(style))
{
wxFAIL_MSG( wxT("wxPostScriptDC::FloodFill not implemented.") );
- return FALSE;
+ return false;
}
bool wxPostScriptDC::DoGetPixel (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour * WXUNUSED(col)) const
{
wxFAIL_MSG( wxT("wxPostScriptDC::GetPixel not implemented.") );
- return FALSE;
+ return false;
}
void wxPostScriptDC::DoCrossHair (wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
}
}
-void wxPostScriptDC::DoDrawPolyPolygon (int n, int start[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
+void wxPostScriptDC::DoDrawPolyPolygon (int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
PsPrint( "newpath\n" );
int ofs = 0;
- for (int i = 0; i < n; ofs += start[i++])
+ for (int i = 0; i < n; ofs += count[i++])
{
wxCoord xx = LogicalToDeviceX(points[ofs].x + xoffset);
wxCoord yy = LogicalToDeviceY(points[ofs].y + yoffset);
CalcBoundingBox( points[ofs].x + xoffset, points[ofs].y + yoffset );
- for (int j = 1; j < start[i]; j++)
+ for (int j = 1; j < count[i]; j++)
{
xx = LogicalToDeviceX(points[ofs+j].x + xoffset);
yy = LogicalToDeviceY(points[ofs+j].y + yoffset);
PsPrint( "newpath\n" );
int ofs = 0;
- for (int i = 0; i < n; ofs += start[i++])
+ for (int i = 0; i < n; ofs += count[i++])
{
wxCoord xx = LogicalToDeviceX(points[ofs].x + xoffset);
wxCoord yy = LogicalToDeviceY(points[ofs].y + yoffset);
CalcBoundingBox( points[ofs].x + xoffset, points[ofs].y + yoffset );
- for (int j = 1; j < start[i]; j++)
+ for (int j = 1; j < count[i]; j++)
{
xx = LogicalToDeviceX(points[ofs+j].x + xoffset);
yy = LogicalToDeviceY(points[ofs+j].y + yoffset);
CalcBoundingBox( LogicalToDeviceX(points[i].x+xoffset), LogicalToDeviceY(points[i].y+yoffset));
}
- PsPrintf( wxT("newpath\n"
- "%d %d moveto\n"),
+ PsPrintf( wxT("newpath\n")
+ wxT("%d %d moveto\n"),
LogicalToDeviceX(points[0].x+xoffset),
LogicalToDeviceY(points[0].y+yoffset) );
-
+
for (i = 1; i < n; i++)
{
PsPrintf( wxT("%d %d lineto\n"),
LogicalToDeviceX(points[i].x+xoffset),
LogicalToDeviceY(points[i].y+yoffset) );
}
-
+
PsPrint( "stroke\n" );
}
void wxPostScriptDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y )
{
- DrawBitmap( icon, x, y, TRUE );
+ DrawBitmap( icon, x, y, true );
}
/* this has to be char, not wxChar */
}
}
+ // We may legitimately call SetFont before BeginDoc
+ if (!m_pstream)
+ return;
+
PsPrint( name );
PsPrint( " reencodeISO def\n" );
PsPrint( name );
PsPrint( " findfont\n" );
-
+
char buffer[100];
sprintf( buffer, "%f scalefont setfont\n", LogicalToDeviceYRel(m_font.GetPointSize() * 1000) / 1000.0F);
// this is a hack - we must scale font size (in pts) according to m_scaleY but
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",
if (buffer[i] == ',') buffer[i] = '.';
PsPrint( buffer );
-
+
m_currentRed = red;
m_currentBlue = blue;
m_currentGreen = green;
redPS, greenPS, bluePS );
for (int i = 0; i < 100; i++)
if (buffer[i] == ',') buffer[i] = '.';
-
+
PsPrint( buffer );
m_currentRed = red;
#include "wx/x11/private.h"
#endif
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
#include "wx/fontutil.h"
#include <pango/pangoft2.h>
#include <freetype/ftglyph.h>
#endif
+
+#if wxUSE_PANGO
+static void InitializePangoContext(PangoContext *context)
+{
+#ifdef __WXGTK__
+ pango_context_set_base_dir(context,
+ gtk_widget_get_default_direction() == GTK_TEXT_DIR_LTR ?
+ PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
+ pango_context_set_language(context, gtk_get_default_language());
+#else
+ // FIXME: assuming LTR is incorrect!
+ pango_context_set_base_dir(context, PANGO_DIRECTION_LTR);
+ wxString lang = wxGetLocale()->GetCanonicalName();
+ pango_context_set_language(context,
+ pango_language_from_string(lang.ToAscii()));
+#endif
+}
+#endif
+
void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
int ps_dpi = 72;
int pango_dpi = 600;
PangoContext *context = pango_ft2_get_context ( pango_dpi, pango_dpi );
+
+ InitializePangoContext(context);
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);
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;
PsPrint(c);
}
}
-
+
PsPrint( ") show\n" );
-
+
if (m_font.GetUnderlined())
{
wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
PsPrintf( wxT("%d %d moveto\n"),
LogicalToDeviceX(x), LogicalToDeviceY(y));
-
+
char buffer[100];
sprintf(buffer, "%.8f rotate\n", angle);
size_t i;
if (buffer[i] == ',') buffer[i] = '.';
}
PsPrint( buffer);
-
+
PsPrint( "(" );
const wxWX2MBbuf textbuf = text.mb_str();
size_t len = strlen(textbuf);
PsPrint(c);
}
}
-
+
PsPrint( ") show\n" );
-
+
sprintf( buffer, "%.8f rotate\n", -angle );
for (i = 0; i < 100; i++)
{
if (buffer[i] == ',') buffer[i] = '.';
}
PsPrint( buffer );
-
+
if (m_font.GetUnderlined())
{
wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
}
PsPrint( buffer );
}
-
+
CalcBoundingBox( x, y );
CalcBoundingBox( x + size * text.Length() * 2/3 , y );
}
next-to-last and last point respectively, in the point list
*/
- PsPrintf( wxT("%d %d lineto\n"
- "stroke\n"),
+ PsPrintf( wxT("%d %d lineto\n")
+ wxT("stroke\n"),
LogicalToDeviceX((wxCoord)c), LogicalToDeviceY((wxCoord)d) );
}
bool wxPostScriptDC::StartDoc( const wxString& message )
{
- wxCHECK_MSG( m_ok, FALSE, wxT("invalid postscript dc") );
-
- if ( m_printData.GetPrintMode() == wxPRINT_MODE_FILE )
+ wxCHECK_MSG( m_ok, false, wxT("invalid postscript dc") );
+
+ if (m_printData.GetPrintMode() != wxPRINT_MODE_STREAM )
{
- if (m_printData.GetFilename() == wxT(""))
+ if (m_printData.GetFilename() == wxEmptyString)
{
wxString filename = wxGetTempFileName( wxT("ps") );
m_printData.SetFilename(filename);
if (!m_pstream)
{
wxLogError( _("Cannot open file for PostScript printing!"));
- m_ok = FALSE;
- return FALSE;
+ m_ok = false;
+ return false;
}
}
- m_ok = TRUE;
+ m_ok = true;
m_title = message;
PsPrint( "%!PS-Adobe-2.0\n" );
PsPrintf( wxT("%%%%Title: %s\n"), m_title.c_str() );
- PsPrint( "%%Creator: wxWindows PostScript renderer\n" );
+ PsPrint( "%%Creator: wxWidgets PostScript renderer\n" );
PsPrintf( wxT("%%%%CreationDate: %s\n"), wxNow().c_str() );
if (m_printData.GetOrientation() == wxLANDSCAPE)
PsPrint( "%%Orientation: Landscape\n" );
wxPageNumber = 1;
m_pageNumber = 1;
- return TRUE;
+ return true;
}
void wxPostScriptDC::EndDoc ()
if (m_clipping)
{
- m_clipping = FALSE;
+ m_clipping = false;
PsPrint( "grestore\n" );
}
PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx, ury );
#endif
-#if defined(__X__) || defined(__WXGTK__)
+#ifndef __WXMSW__
+ wxPostScriptPrintNativeData *data =
+ (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+
if (m_ok && (m_printData.GetPrintMode() == wxPRINT_MODE_PRINTER))
{
wxString command;
- command += m_printData.GetPrinterCommand();
+ command += data->GetPrinterCommand();
command += wxT(" ");
- command += m_printData.GetPrinterOptions();
+ command += data->GetPrinterOptions();
command += wxT(" ");
command += m_printData.GetFilename();
- wxExecute( command, TRUE );
+ wxExecute( command, true );
wxRemoveFile( m_printData.GetFilename() );
}
#endif
wxCoord translate_x, translate_y;
double scale_x, scale_y;
- translate_x = (wxCoord)m_printData.GetPrinterTranslateX();
- translate_y = (wxCoord)m_printData.GetPrinterTranslateY();
+ wxPostScriptPrintNativeData *data =
+ (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+
+ translate_x = (wxCoord)data->GetPrinterTranslateX();
+ translate_y = (wxCoord)data->GetPrinterTranslateY();
- scale_x = m_printData.GetPrinterScaleX();
- scale_y = m_printData.GetPrinterScaleY();
+ scale_x = data->GetPrinterScaleX();
+ scale_y = data->GetPrinterScaleY();
if (m_printData.GetOrientation() == wxLANDSCAPE)
{
wxCoord xsrc, wxCoord ysrc,
int rop, bool WXUNUSED(useMask), wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask) )
{
- wxCHECK_MSG( m_ok, FALSE, wxT("invalid postscript dc") );
+ wxCHECK_MSG( m_ok, false, wxT("invalid postscript dc") );
- wxCHECK_MSG( source, FALSE, wxT("invalid source dc") );
+ wxCHECK_MSG( source, false, wxT("invalid source dc") );
/* blit into a bitmap */
wxBitmap bitmap( (int)fwidth, (int)fheight );
/* draw bitmap. scaling and positioning is done there */
DrawBitmap( bitmap, xdest, ydest );
- return TRUE;
+ return true;
}
wxCoord wxPostScriptDC::GetCharHeight() const
int pango_dpi = 600;
PangoContext *context = pango_ft2_get_context ( pango_dpi, pango_dpi );
+ InitializePangoContext(context);
+
double scale = pango_dpi / wx_dpi;
scale /= m_userScaleY;
- pango_context_set_language (context, pango_language_from_string ("en_US"));
- pango_context_set_base_dir (context, PANGO_DIRECTION_LTR );
-
PangoLayout *layout = pango_layout_new (context);
PangoFontDescription *desc = fontToUse->GetNativeFontInfo()->description;
const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
#endif
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
- PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
PangoRectangle rect;
- pango_layout_line_get_extents(line, NULL, &rect);
+ pango_layout_get_extents(layout, NULL, &rect);
- if (x) (*x) = (wxCoord) ( rect.width / PANGO_SCALE / scale );
- if (y) (*y) = (wxCoord) ( rect.height / PANGO_SCALE / scale );
+ if (x) (*x) = (wxCoord) ( PANGO_PIXELS(rect.width) / scale );
+ if (y) (*y) = (wxCoord) ( PANGO_PIXELS(rect.height) / scale );
if (descent)
{
- // Do something about metrics here
- (*descent) = 0;
+ PangoLayoutIter *iter = pango_layout_get_iter(layout);
+ int baseline = pango_layout_iter_get_baseline(iter);
+ pango_layout_iter_free(iter);
+ *descent = wxCoord(*y - PANGO_PIXELS(baseline) / scale);
}
if (externalLeading) (*externalLeading) = 0; // ??
/
/ example:
/
- / wxPostScriptDC dc(NULL, TRUE);
+ / wxPostScriptDC dc(NULL, true);
/ if (dc.Ok()){
/ wxSetAFMPath("d:\\wxw161\\afm\\");
/ dc.StartDoc("Test");
FILE *afmFile = NULL;
+ wxPostScriptPrintNativeData *data =
+ (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+
// Get the directory of the AFM files
wxString afmName;
- if (!m_printData.GetFontMetricPath().IsEmpty())
+ if (!data->GetFontMetricPath().IsEmpty())
{
- afmName = m_printData.GetFontMetricPath();
+ afmName = data->GetFontMetricPath();
afmName << wxFILE_SEP_PATH << name;
afmFile = wxFopen(afmName,wxT("r"));
}
void wxPostScriptDC::PsPrint( const char* psdata )
{
- switch( m_printData.GetPrintMode() )
+ wxPostScriptPrintNativeData *data =
+ (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+
+ switch (m_printData.GetPrintMode())
{
#if wxUSE_STREAMS
// append to output stream
case wxPRINT_MODE_STREAM:
{
- wxOutputStream* outputstream = m_printData.GetOutputStream();
+ wxOutputStream* outputstream = data->GetOutputStream();
wxCHECK_RET( outputstream, wxT("invalid outputstream") );
outputstream->Write( psdata, strlen( psdata ) );
}
void wxPostScriptDC::PsPrint( int ch )
{
- switch( m_printData.GetPrintMode() )
+ wxPostScriptPrintNativeData *data =
+ (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+
+ switch (m_printData.GetPrintMode())
{
#if wxUSE_STREAMS
// append to output stream
case wxPRINT_MODE_STREAM:
{
- wxOutputStream* outputstream = m_printData.GetOutputStream();
+ wxOutputStream* outputstream = data->GetOutputStream();
wxCHECK_RET( outputstream, wxT("invalid outputstream") );
outputstream->PutC( ch );
}
{
wxInitializePrintSetupData();
- return TRUE;
+ return true;
}
void wxPostScriptModule::OnExit()
{
- wxInitializePrintSetupData(FALSE);
+ wxInitializePrintSetupData(false);
}
#endif
// WXWIN_COMPATIBILITY_2_2