diff --git a/xvaga/xvaga.cpp b/xvaga/xvaga.cpp index f70688f5e..2954b8e63 100755 --- a/xvaga/xvaga.cpp +++ b/xvaga/xvaga.cpp @@ -442,7 +442,7 @@ wxDC& TDC::GetDC(bool bPaint) if (_dirty < 0 || FontChanged()) { - _dc->SetFont(_font.Font(_dc)); + _dc->SetFont(_font.Font(_dc, (WINDOW)_owner)); _real_font = _font; int height, desc, lead; @@ -1713,7 +1713,7 @@ BOOLEAN xvt_dm_post_font_sel(WINDOW win, XVT_FNTID font_id, PRINT_RCD *precp, un { TFontId& font = *(TFontId*)font_id; wxFontData data; - data.SetInitialFont(font.Font(NULL)); + data.SetInitialFont(font.Font(NULL, win)); data.EnableEffects(FALSE); wxFontDialog dlg(_task_win, &data); BOOLEAN ok = dlg.ShowModal() == wxID_OK; @@ -1987,14 +1987,14 @@ bool TFontId::Underline() const } -wxFont& TFontId::Font(wxDC* dc) const +wxFont& TFontId::Font(wxDC* dc, WINDOW win) const { int nSize = PointSize(); - if (m_win == _print_win) + if (win == _print_win) { static wxDC* lastDC = NULL; static double dPrintScale = 1.0; - +/* if (dc != lastDC) { const wxSize ppi = dc->GetPPI(); @@ -2010,9 +2010,10 @@ wxFont& TFontId::Font(wxDC* dc) const const int nFontSize = int(12.0 * nScale); // First guess for PointSize if (nFontSize == nBestSize) break; - wxFont courier(nFontSize, wxMODERN, wxNORMAL, wxNORMAL); + //wxFont courier(nFontSize, wxTELETYPE, wxNORMAL, wxNORMAL); + wxFont courier(nFontSize, Family(), wxNORMAL, wxNORMAL); dc->SetFont(courier); - int tw; dc->GetTextExtent("0123456789", &tw, NULL); + int tw; dc->GetTextExtent("MMMMMMMMMM", &tw, NULL); if (tw != nLastTextWidth) nLastTextWidth = tw; // Happens with Generic/Text Only else @@ -2035,7 +2036,35 @@ wxFont& TFontId::Font(wxDC* dc) const dPrintScale = nBestSize / 12.0; lastDC = dc; } - nSize = int(nSize * dPrintScale); +*/ + if (dc != lastDC) + { + const wxSize ppi = dc->GetPPI(); + + const int nTarget = ppi.x; + const int cpi = 120 / nSize; + + wxString str = "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"; + str.Truncate(cpi); + + int nMin = 1, nMax = nSize*8; + while (nMin < nMax) + { + const int nFontSize = (nMin+nMax)/2; + wxFont courier(nFontSize, Family(), wxNORMAL, wxNORMAL, FALSE, FaceName()); + dc->SetFont(courier); + int tw; dc->GetTextExtent(str, &tw, NULL); + if (tw == nTarget) + break; + if (tw > nTarget) + nMax = nFontSize-1; + else + nMin = nFontSize+1; + } + dPrintScale = double((nMin+nMax)/2) / double(nSize); + lastDC = dc; + } + nSize = int(nSize * dPrintScale + 0.5); } const int nWeight = (m_wMask & XVT_FS_BOLD) ? wxBOLD : wxNORMAL; @@ -2509,7 +2538,7 @@ void xvt_font_get_metrics(XVT_FNTID font_id, int *leadingp, int *ascentp, int *d CAST_DC(win, dc); const wxString str = "Mq"; int height, desc, lead; - dc.GetTextExtent(str, NULL, &height, &desc, &lead, &font.Font(&dc)); + dc.GetTextExtent(str, NULL, &height, &desc, &lead, &font.Font(&dc, win)); if (leadingp) *leadingp = lead; if (ascentp) diff --git a/xvaga/xvintern.h b/xvaga/xvintern.h index e9c275fd4..054ed1f19 100755 --- a/xvaga/xvintern.h +++ b/xvaga/xvintern.h @@ -31,7 +31,7 @@ public: int Family() const; void Copy(const wxFont& rFont); - wxFont& Font(wxDC* dc) const; + wxFont& Font(wxDC* dc, WINDOW w) const; TFontId& operator=(const TFontId& f) { Copy(f); return *this; } bool operator==(const TFontId& f) const { return IsEqual(f); } @@ -69,7 +69,7 @@ public: int GetFontDelta() const { return _deltaf; } virtual wxDC& GetDC(bool bPaint = false); - void KillDC(); + virtual void KillDC(); TDC(wxWindow* owner); virtual ~TDC(); }; @@ -78,6 +78,7 @@ class TPrintDC : public TDC { public: virtual wxDC& GetDC(bool); + virtual void KillDC(); TPrintDC(wxWindow* owner); virtual ~TPrintDC(); }; diff --git a/xvaga/xvtextra.cpp b/xvaga/xvtextra.cpp index 8385e0430..2fc21fe01 100755 --- a/xvaga/xvtextra.cpp +++ b/xvaga/xvtextra.cpp @@ -203,6 +203,11 @@ wxDC& TPrintDC::GetDC(bool) return TDC::GetDC(false); } +void TPrintDC::KillDC() +{ + _dc = NULL; // _dc is owned by wxPrintout +} + TPrintDC::TPrintDC(wxWindow* owner) : TDC(owner) { }