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:
parent
d2cbf07a3d
commit
f999a0e56a
@ -1973,7 +1973,7 @@ int TFontId::Family() const
|
|||||||
return wxMODERN;
|
return wxMODERN;
|
||||||
if (m_strFace == XVT_FFN_SYSTEM)
|
if (m_strFace == XVT_FFN_SYSTEM)
|
||||||
return wxDEFAULT;
|
return wxDEFAULT;
|
||||||
return wxROMAN;
|
return wxSWISS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TFontId::Style() const
|
int TFontId::Style() const
|
||||||
@ -1994,49 +1994,6 @@ wxFont& TFontId::Font(wxDC* dc, WINDOW win) const
|
|||||||
{
|
{
|
||||||
static wxDC* lastDC = NULL;
|
static wxDC* lastDC = NULL;
|
||||||
static double dPrintScale = 1.0;
|
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)
|
if (dc != lastDC)
|
||||||
{
|
{
|
||||||
const wxSize ppi = dc->GetPPI();
|
const wxSize ppi = dc->GetPPI();
|
||||||
@ -2048,23 +2005,34 @@ wxFont& TFontId::Font(wxDC* dc, WINDOW win) const
|
|||||||
str.Truncate(cpi);
|
str.Truncate(cpi);
|
||||||
|
|
||||||
int nMin = 1, nMax = nSize*8;
|
int nMin = 1, nMax = nSize*8;
|
||||||
while (nMin < nMax)
|
int nBest = 0;
|
||||||
|
while (nMin <= nMax)
|
||||||
{
|
{
|
||||||
const int nFontSize = (nMin+nMax)/2;
|
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);
|
dc->SetFont(courier);
|
||||||
int tw; dc->GetTextExtent(str, &tw, NULL);
|
int tw; dc->GetTextExtent(str, &tw, NULL);
|
||||||
if (tw == nTarget)
|
if (tw <= nTarget)
|
||||||
break;
|
{
|
||||||
if (tw > nTarget)
|
|
||||||
nMax = nFontSize-1;
|
|
||||||
else
|
|
||||||
nMin = nFontSize+1;
|
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;
|
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;
|
const int nWeight = (m_wMask & XVT_FS_BOLD) ? wxBOLD : wxNORMAL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user