Patch level : 2.2
Files correlati : Ricompilazione Demo : [ ] Commento : Aggiustamento calcoli font di stampa git-svn-id: svn://10.65.10.50/trunk@13372 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
9a2a53a6d7
commit
b3c9ec4baa
@ -172,8 +172,7 @@ XVT_FNTID xvt_default_font(bool bold)
|
||||
TString font_ser_desc(font.get("FontDesc"));
|
||||
if (font_ser_desc.empty())
|
||||
{
|
||||
const char* name = "Courier";
|
||||
|
||||
const char* name = "Courier New";
|
||||
// Tenta di usare il Verdana se possibile
|
||||
if (pc.right > 800 && is_xvt_font("Verdana"))
|
||||
name = "Verdana";
|
||||
@ -183,7 +182,7 @@ XVT_FNTID xvt_default_font(bool bold)
|
||||
font.set("FontDesc", font_ser_desc); // Salva definitivamente il font
|
||||
}
|
||||
|
||||
xvt_font_deserialize(DEF_FONT, (char *)(const char *) font_ser_desc);
|
||||
xvt_font_deserialize(DEF_FONT, font_ser_desc);
|
||||
xvt_font_map_using_default(DEF_FONT);
|
||||
CHECK(xvt_font_is_mapped(DEF_FONT), "Can't map native font");
|
||||
|
||||
|
@ -28,7 +28,7 @@ int compute_font_match(WINDOW win, int size, int ppi, int cpi)
|
||||
const int me = (mi+ma)/2;
|
||||
|
||||
XVT_FNTID fontid = xvt_font_create();
|
||||
xvt_font_set_family(fontid, "Courier New");
|
||||
xvt_font_set_family(fontid, DEFAULT_FONT_NAME);
|
||||
xvt_font_set_size(fontid, me);
|
||||
xvt_dwin_set_font(win, fontid);
|
||||
const int width = xvt_dwin_get_text_width(win, emme, -1);
|
||||
@ -75,7 +75,6 @@ XVT_FNTID TReport_font::get_xvt_font(const TWindow& win) const
|
||||
myself.unmap();
|
||||
myself._fontid = fontid;
|
||||
myself._win_mapped = w;
|
||||
//xvt_dwin_get_font_metrics(w, &myself._leading, &myself._ascent, &myself._descent);
|
||||
}
|
||||
return _fontid;
|
||||
}
|
||||
@ -100,7 +99,6 @@ XVT_FNTID TReport_font::get_preview_font(const TWindow& win, const TPoint& res)
|
||||
myself.unmap();
|
||||
myself._fontid = fontid;
|
||||
myself._win_mapped = w;
|
||||
//xvt_dwin_get_font_metrics(_win_mapped, &myself._leading, &myself._ascent, &myself._descent);
|
||||
}
|
||||
return _fontid;
|
||||
}
|
||||
@ -185,7 +183,7 @@ bool TReport_font::load(const TXmlItem& item)
|
||||
|
||||
TReport_font::TReport_font() : _win_mapped(NULL_WIN), _fontid(NULL)
|
||||
{
|
||||
create("Courier New", DEFAULT_FONT_SIZE, XVT_FS_NONE);
|
||||
create(DEFAULT_FONT_NAME, DEFAULT_FONT_SIZE, XVT_FS_NONE);
|
||||
}
|
||||
|
||||
TReport_font::TReport_font(const TReport_font& f) : _win_mapped(NULL_WIN), _fontid(NULL)
|
||||
|
@ -29,6 +29,13 @@ class TRectype;
|
||||
// TReport_font
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
// Font di base per i calcoli di impaginazione
|
||||
#ifdef WIN32
|
||||
#define DEFAULT_FONT_NAME "Courier New"
|
||||
#else
|
||||
#define DEFAULT_FONT_NAME "Courier"
|
||||
#endif
|
||||
|
||||
class TReport_font : public TSortable
|
||||
{
|
||||
enum { DEFAULT_FONT_SIZE = 10 };
|
||||
@ -39,7 +46,6 @@ class TReport_font : public TSortable
|
||||
|
||||
WINDOW _win_mapped;
|
||||
XVT_FNTID _fontid;
|
||||
// int _leading, _ascent, _descent;
|
||||
|
||||
protected:
|
||||
virtual int compare(const TSortable& s) const;
|
||||
|
@ -19,12 +19,14 @@ static bool _print_aborted = false;
|
||||
|
||||
static void advanced_draw_justified_text_line(TWindow& win, const char* text, short x, short y, short dx)
|
||||
{
|
||||
TString txt(text); txt.rtrim();
|
||||
TString256 txt(text); txt.rtrim();
|
||||
int spaces = 0;
|
||||
for (int s = 0; txt[s]; s++)
|
||||
if (isspace(txt[s])) spaces++;
|
||||
|
||||
WINDOW w = win.win();
|
||||
|
||||
// Il testo e' giustificabile se ha degli spazi ed occupa meno della riga
|
||||
if (spaces > 0)
|
||||
{
|
||||
const int tw = xvt_dwin_get_text_width(w, txt, -1);
|
||||
@ -34,24 +36,23 @@ static void advanced_draw_justified_text_line(TWindow& win, const char* text, sh
|
||||
const double kspc = double(dx - tw) / spaces;
|
||||
int start = 0;
|
||||
double kx = x;
|
||||
for (int i = 0; txt[i]; i++)
|
||||
for (int i = 0; txt[i]; i++) if (isspace(txt[i]))
|
||||
{
|
||||
if (isspace(txt[i]))
|
||||
{
|
||||
const bool last_word = txt[i+1] == '\0';
|
||||
const TString& parola = txt.sub(start, i + (last_word ? 0 : 1));
|
||||
const int lw = xvt_dwin_get_text_width(w, parola, -1);
|
||||
if (last_word) // ultima parola
|
||||
kx = x+dx-lw;
|
||||
xvt_dwin_draw_text(w, int(kx+0.5), y, parola, -1);
|
||||
kx += lw + kspc;
|
||||
start = i+1;
|
||||
}
|
||||
const bool last_word = txt[i+1] == '\0';
|
||||
const TString& parola = txt.sub(start, i + (last_word ? 0 : 1));
|
||||
const int lw = xvt_dwin_get_text_width(w, parola, -1);
|
||||
if (last_word) // ultima parola
|
||||
kx = x+dx-lw;
|
||||
xvt_dwin_draw_text(w, int(kx+0.5), y, parola, -1);
|
||||
kx += lw + kspc;
|
||||
start = i+1;
|
||||
}
|
||||
}
|
||||
else
|
||||
xvt_dwin_draw_text(w, x, y, txt, -1); // Stringa che deborda dalla riga
|
||||
}
|
||||
else
|
||||
xvt_dwin_draw_text(w, x, y, txt, -1);
|
||||
xvt_dwin_draw_text(w, x, y, txt, -1); // Stringa senza spazi
|
||||
}
|
||||
|
||||
void advanced_draw_text_line(TWindow& win, const char* text, const RCT& r, char halign, char valign)
|
||||
@ -106,6 +107,18 @@ void advanced_draw_text_line(TWindow& win, const char* text, const RCT& r, char
|
||||
xvt_dwin_set_clip(w, NULL);
|
||||
}
|
||||
|
||||
bool finisce_per_punto(const TString& str)
|
||||
{
|
||||
bool yes = false;
|
||||
const int len = str.len();
|
||||
if (len > 0)
|
||||
{
|
||||
const char last = str[len-1];
|
||||
yes = strchr(".!?:", last) != NULL;
|
||||
}
|
||||
return yes;
|
||||
}
|
||||
|
||||
void advanced_draw_paragraph(TWindow& win, const TString_array& para, const RCT& rct,
|
||||
char halign, char valign, int default_10row_height)
|
||||
{
|
||||
@ -135,21 +148,27 @@ void advanced_draw_paragraph(TWindow& win, const TString_array& para, const RCT&
|
||||
const int top = ybase + (ky10 * row) / 10;
|
||||
if (top < rct.bottom)
|
||||
{
|
||||
RCT rctline = rct;
|
||||
rctline.top = top;
|
||||
rctline.bottom = top + ky10 / 10;
|
||||
const TString& line = para.row(row);
|
||||
char ha = halign;
|
||||
if (ha == 'J' && row == rows-1) // Ultima riga non "giustificabile"
|
||||
ha = 'L';
|
||||
advanced_draw_text_line(win, line, rctline, ha, 'T');
|
||||
if (!line.blank())
|
||||
{
|
||||
RCT rctline = rct;
|
||||
rctline.top = top;
|
||||
rctline.bottom = top + ky10 / 10;
|
||||
char ha = halign;
|
||||
if (ha == 'J' && (row == rows-1 || finisce_per_punto(line)))
|
||||
ha = 'L';
|
||||
advanced_draw_text_line(win, line, rctline, ha, 'T');
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (halign == 'J') halign = 'L';
|
||||
advanced_draw_text_line(win, para.row(0), rct, halign, valign);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
@ -1175,7 +1194,7 @@ bool TBook::print_page(TWindow& win, size_t page)
|
||||
}
|
||||
if (str.starts_with("<font "))
|
||||
{
|
||||
TString80 name = XVT_FFN_COURIER; get_xml_string(str, "name", name);
|
||||
TString80 name = DEFAULT_FONT_NAME; get_xml_string(str, "name", name);
|
||||
const int size = get_xml_int(str, "size", 12);
|
||||
const XVT_FONT_STYLE_MASK style = get_xml_int(str, "style", 0);
|
||||
TReport_font font; font.create(name, size, style);
|
||||
|
@ -697,9 +697,38 @@ int TString::compare(
|
||||
|
||||
bool TString::starts_with(const char* s, bool ignorecase) const
|
||||
{
|
||||
return compare(s, strlen(s), ignorecase) == 0;
|
||||
return (s && *s) ? (compare(s, strlen(s), ignorecase) == 0) : true;
|
||||
}
|
||||
|
||||
bool TString::ends_with(const char* s, bool ignorecase) const
|
||||
{
|
||||
const int mylen = len();
|
||||
const int slen = (s && *s) ? strlen(s) : 0;
|
||||
bool yes = false;
|
||||
if (slen > 0 && slen <= mylen)
|
||||
{
|
||||
if (slen > 1)
|
||||
{
|
||||
if (slen != mylen)
|
||||
{
|
||||
const TString& fine = right(slen);
|
||||
yes = fine.compare(s, slen, ignorecase) == 0;
|
||||
}
|
||||
else
|
||||
yes = compare(s, -1, ignorecase) == 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ignorecase)
|
||||
yes = toupper(_str[mylen-1]) == toupper(s[slen-1]);
|
||||
else
|
||||
yes = _str[mylen-1] == s[slen-1];
|
||||
}
|
||||
}
|
||||
return yes;
|
||||
}
|
||||
|
||||
|
||||
// Certified 100%
|
||||
// @doc EXTERNAL
|
||||
|
||||
|
@ -269,6 +269,8 @@ public:
|
||||
int compare(const char* s, int max = -1, bool ignorecase = FALSE) const;
|
||||
// @cmember Controlla se la strinvga comincia per s
|
||||
bool starts_with(const char* s, bool ignorecase = FALSE) const;
|
||||
// @cmember Controlla se la strinvga finisce per s
|
||||
bool ends_with(const char* s, bool ignorecase = FALSE) const;
|
||||
};
|
||||
|
||||
// @doc EXTERNAL
|
||||
|
Loading…
x
Reference in New Issue
Block a user