Patch level : 2.1 nopatch

Files correlati     : xvaga.dll
Ricompilazione Demo : [ ]
Commento            :

Migliorato calcolo dimensioni font da stampare


git-svn-id: svn://10.65.10.50/trunk@11883 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2004-03-18 08:59:34 +00:00
parent d2cbf07a3d
commit f999a0e56a

@ -1973,7 +1973,7 @@ int TFontId::Family() const
return wxMODERN;
if (m_strFace == XVT_FFN_SYSTEM)
return wxDEFAULT;
return wxROMAN;
return wxSWISS;
}
int TFontId::Style() const
@ -1994,49 +1994,6 @@ wxFont& TFontId::Font(wxDC* dc, WINDOW win) const
{
static wxDC* lastDC = NULL;
static double dPrintScale = 1.0;
/*
if (dc != lastDC)
{
const wxSize ppi = dc->GetPPI();
dPrintScale = ppi.x / 96.0; // First guess for scaling factor
int nLastTextWidth = 0;
int nBestSize = 0;
double nMin = dPrintScale-0.1;
double nMax = dPrintScale+0.1;
while (true)
{
const double nScale = (nMin+nMax)/2.0;
const int nFontSize = int(12.0 * nScale); // First guess for PointSize
if (nFontSize == nBestSize)
break;
//wxFont courier(nFontSize, wxTELETYPE, wxNORMAL, wxNORMAL);
wxFont courier(nFontSize, Family(), wxNORMAL, wxNORMAL);
dc->SetFont(courier);
int tw; dc->GetTextExtent("MMMMMMMMMM", &tw, NULL);
if (tw != nLastTextWidth)
nLastTextWidth = tw; // Happens with Generic/Text Only
else
{
if (nBestSize == 0)
nBestSize = nFontSize;
break;
}
if (tw > ppi.x)
{
nMax = nScale;
}
else
{
nMin = nScale;
nBestSize = nFontSize;
}
}
dPrintScale = nBestSize / 12.0;
lastDC = dc;
}
*/
if (dc != lastDC)
{
const wxSize ppi = dc->GetPPI();
@ -2048,23 +2005,34 @@ wxFont& TFontId::Font(wxDC* dc, WINDOW win) const
str.Truncate(cpi);
int nMin = 1, nMax = nSize*8;
while (nMin < nMax)
int nBest = 0;
while (nMin <= nMax)
{
const int nFontSize = (nMin+nMax)/2;
wxFont courier(nFontSize, Family(), wxNORMAL, wxNORMAL, FALSE, FaceName());
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
if (tw <= nTarget)
{
nMin = nFontSize+1;
nBest = nFontSize;
if (tw == nTarget)
break;
}
else
nMax = nFontSize-1;
}
dPrintScale = double((nMin+nMax)/2) / double(nSize);
if (nBest == 0)
nBest = nMax;
dPrintScale = double(nBest) / double(nSize);
lastDC = dc;
}
nSize = int(nSize * dPrintScale + 0.5);
nSize = (int)(nSize * dPrintScale + 0.5);
#ifdef WIN32
// In Windows rendo negativa la dimensione perche' e' piu' preciso!
nSize = -nSize;
#endif
}
const int nWeight = (m_wMask & XVT_FS_BOLD) ? wxBOLD : wxNORMAL;