-/* You might use THIS code to set the printer DC to ROUGHLY reflect
- * the screen text size. This page also draws lines of actual length 5cm
- * on the page.
- */
- // Get the logical pixels per inch of screen and printer
- int ppiScreenX, ppiScreenY;
- GetPPIScreen(&ppiScreenX, &ppiScreenY);
- int ppiPrinterX, ppiPrinterY;
- GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);
-
- // This scales the DC so that the printout roughly represents the
- // the screen scaling. The text point size _should_ be the right size
- // but in fact is too small for some reason. This is a detail that will
- // need to be addressed at some point but can be fudged for the
- // moment.
- float scale = (float)((float)ppiPrinterX/(float)ppiScreenX);
-
- // Now we have to check in case our real page size is reduced
- // (e.g. because we're drawing to a print preview memory DC)
- int pageWidth, pageHeight;
- int w, h;
- dc->GetSize(&w, &h);
- GetPageSizePixels(&pageWidth, &pageHeight);
-
- // If printer pageWidth == current DC width, then this doesn't
- // change. But w might be the preview bitmap width, so scale down.
- float overallScale = scale * (float)(w/(float)pageWidth);
- dc->SetUserScale(overallScale, overallScale);
-
- // Calculate conversion factor for converting millimetres into
- // logical units.
- // There are approx. 25.1 mm to the inch. There are ppi
- // device units to the inch. Therefore 1 mm corresponds to
- // ppi/25.1 device units. We also divide by the
- // screen-to-printer scaling factor, because we need to
- // unscale to pass logical units to DrawLine.
-
- // Draw 50 mm by 50 mm L shape
- float logUnitsFactor = (float)(ppiPrinterX/(scale*25.1));
- float logUnits = (float)(50*logUnitsFactor);
- dc->SetPen(wxBLACK_PEN);
- dc->DrawLine(50.0, 50.0, (float)(50.0 + logUnits), 50.0);
- dc->DrawLine(50.0, 50.0, 50.0, (float)(50.0 + logUnits));
-
- dc->SetFont(itemFont);
- dc->SetBackgroundMode(wxTRANSPARENT);
-
- dc->DrawText("Some test text", 200.0, 200.0);
-
- // TESTING
-
- int leftMargin = 20;
- int rightMargin = 20;
- int topMargin = 20;
- int bottomMargin = 20;
-
- int pageWidthMM, pageHeightMM;
- GetPageSizeMM(&pageWidthMM, &pageHeightMM);
-
- float leftMarginLogical = (float)(logUnitsFactor*leftMargin);
- float topMarginLogical = (float)(logUnitsFactor*topMargin);
- float bottomMarginLogical = (float)(logUnitsFactor*(pageHeightMM - bottomMargin));
- float rightMarginLogical = (float)(logUnitsFactor*(pageWidthMM - rightMargin));
-
- dc->SetPen(wxBLACK_PEN);
- dc->DrawLine(leftMarginLogical, topMarginLogical, rightMarginLogical, topMarginLogical);
- dc->DrawLine(leftMarginLogical, bottomMarginLogical, rightMarginLogical, bottomMarginLogical);
-
- WritePageHeader(this, dc, "A header", logUnitsFactor);
+ // You might use THIS code to set the printer DC to ROUGHLY reflect
+ // the screen text size. This page also draws lines of actual length
+ // 5cm on the page.
+
+ // Get the logical pixels per inch of screen and printer
+ int ppiScreenX, ppiScreenY;
+ GetPPIScreen(&ppiScreenX, &ppiScreenY);
+ int ppiPrinterX, ppiPrinterY;
+ GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);
+
+ // This scales the DC so that the printout roughly represents the
+ // the screen scaling. The text point size _should_ be the right size
+ // but in fact is too small for some reason. This is a detail that will
+ // need to be addressed at some point but can be fudged for the
+ // moment.
+ float scale = (float)((float)ppiPrinterX/(float)ppiScreenX);
+
+ // Now we have to check in case our real page size is reduced
+ // (e.g. because we're drawing to a print preview memory DC)
+ int pageWidth, pageHeight;
+ int w, h;
+ dc->GetSize(&w, &h);
+ GetPageSizePixels(&pageWidth, &pageHeight);
+
+ // If printer pageWidth == current DC width, then this doesn't
+ // change. But w might be the preview bitmap width, so scale down.
+ float overallScale = scale * (float)(w/(float)pageWidth);
+ dc->SetUserScale(overallScale, overallScale);
+
+ // Calculate conversion factor for converting millimetres into
+ // logical units.
+ // There are approx. 25.1 mm to the inch. There are ppi
+ // device units to the inch. Therefore 1 mm corresponds to
+ // ppi/25.1 device units. We also divide by the
+ // screen-to-printer scaling factor, because we need to
+ // unscale to pass logical units to DrawLine.
+
+ // Draw 50 mm by 50 mm L shape
+ float logUnitsFactor = (float)(ppiPrinterX/(scale*25.1));
+ float logUnits = (float)(50*logUnitsFactor);
+ dc->SetPen(* wxBLACK_PEN);
+ dc->DrawLine(50, 250, (long)(50.0 + logUnits), 250);
+ dc->DrawLine(50, 250, 50, (long)(250.0 + logUnits));
+
+ dc->SetBackgroundMode(wxTRANSPARENT);
+ dc->SetBrush(*wxTRANSPARENT_BRUSH);
+
+ { // GetTextExtent demo:
+ wxString words[7] = {_T("This "), _T("is "), _T("GetTextExtent "), _T("testing "), _T("string. "), _T("Enjoy "), _T("it!")};
+ long w, h;
+ long x = 200, y= 250;
+ wxFont fnt(15, wxSWISS, wxNORMAL, wxNORMAL);
+
+ dc->SetFont(fnt);
+
+ for (int i = 0; i < 7; i++)
+ {
+ wxString word = words[i];
+ word.Remove( word.Len()-1, 1 );
+ dc->GetTextExtent(word, &w, &h);
+ dc->DrawRectangle(x, y, w, h);
+ dc->GetTextExtent(words[i], &w, &h);
+ dc->DrawText(words[i], x, y);
+ x += w;
+ }
+
+ }
+
+ dc->SetFont(wxGetApp().m_testFont);
+
+ dc->DrawText(_T("Some test text"), 200, 300 );
+
+ // TESTING
+
+ int leftMargin = 20;
+ int rightMargin = 20;
+ int topMargin = 20;
+ int bottomMargin = 20;
+
+ int pageWidthMM, pageHeightMM;
+ GetPageSizeMM(&pageWidthMM, &pageHeightMM);
+
+ float leftMarginLogical = (float)(logUnitsFactor*leftMargin);
+ float topMarginLogical = (float)(logUnitsFactor*topMargin);
+ float bottomMarginLogical = (float)(logUnitsFactor*(pageHeightMM - bottomMargin));
+ float rightMarginLogical = (float)(logUnitsFactor*(pageWidthMM - rightMargin));
+
+ dc->SetPen(* wxRED_PEN);
+ dc->DrawLine( (long)leftMarginLogical, (long)topMarginLogical,
+ (long)rightMarginLogical, (long)topMarginLogical);
+ dc->DrawLine( (long)leftMarginLogical, (long)bottomMarginLogical,
+ (long)rightMarginLogical, (long)bottomMarginLogical);
+
+ WritePageHeader(this, dc, _T("A header"), logUnitsFactor);