Eliminati errori di allineamento stampe

Eliminato XVT INTERNAL ERROR al Cancel della stampa


git-svn-id: svn://10.65.10.50/trunk@511 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
villa 1994-11-03 09:03:14 +00:00
parent 9f80c0bc3c
commit 96404663d4
3 changed files with 258 additions and 240 deletions

View File

@ -2,6 +2,14 @@
#include <xvtility.h> #include <xvtility.h>
#include <applicat.h> #include <applicat.h>
static char __spc[] = " "
" "
" "
" "
" "
" ";
#define LEN_SPACES(x) (win_get_text_width(win(),__spc,x))
void TPrintwin::paint_background(long j) void TPrintwin::paint_background(long j)
{ {
@ -23,21 +31,21 @@ void TPrintwin::paint_background(long j)
{ {
case 'v': // verticale intera case 'v': // verticale intera
x1 = (unsigned char)rwd[cnt++]-1; x1 = (unsigned char)rwd[cnt++]-1;
b.h = e.h = x1*_charx+_charx/2+_hofs; b.h = e.h = LEN_SPACES(x1)+LEN_SPACES(1)/2+_hofs;
b.v = rw * _chary + _vofs; e.v = rw * _chary + _vofs; b.v = rw * _chary + _vofs; e.v = rw * _chary + _vofs;
win_move_to(win(),b); win_move_to(win(),b);
win_draw_line(win(),e); win_draw_line(win(),e);
break; break;
case 'o': // verticale pezzo sopra case 'o': // verticale pezzo sopra
x1 = (unsigned char)rwd[cnt++]-1; x1 = (unsigned char)rwd[cnt++]-1;
b.h = e.h = x1*_charx+_charx/2 + _hofs; b.h = e.h = LEN_SPACES(x1)+LEN_SPACES(1)/2 + _hofs;
b.v = rw * _chary + _vofs; e.v = rw * _chary - _chary/2 + _vofs; b.v = rw * _chary + _vofs; e.v = rw * _chary - _chary/2 + _vofs;
win_move_to(win(),b); win_move_to(win(),b);
win_draw_line(win(),e); win_draw_line(win(),e);
break; break;
case 'u': // verticale pezzo sotto case 'u': // verticale pezzo sotto
x1 = (unsigned char)rwd[cnt++]-1; x1 = (unsigned char)rwd[cnt++]-1;
b.h = e.h = x1*_charx+_charx/2 + _hofs; b.h = e.h = LEN_SPACES(x1)+LEN_SPACES(1)/2 + _hofs;
b.v = rw*_chary + _chary/2 + _vofs; e.v = rw * _chary + _vofs; b.v = rw*_chary + _chary/2 + _vofs; e.v = rw * _chary + _vofs;
win_move_to(win(),b); win_move_to(win(),b);
win_draw_line(win(),e); win_draw_line(win(),e);
@ -46,7 +54,7 @@ void TPrintwin::paint_background(long j)
x1 = (unsigned char)rwd[cnt++]-1; x1 = (unsigned char)rwd[cnt++]-1;
x2 = (unsigned char)rwd[cnt++]-1; x2 = (unsigned char)rwd[cnt++]-1;
b.v = e.v = rw*_chary + _chary/2 + _vofs; b.v = e.v = rw*_chary + _chary/2 + _vofs;
b.h = x1*_charx+_hofs; e.h = x2*_charx + _hofs; b.h = LEN_SPACES(x1)+_hofs; e.h = LEN_SPACES(x2)+_hofs;
win_move_to(win(),b); win_move_to(win(),b);
win_draw_line(win(),e); win_draw_line(win(),e);
break; break;
@ -54,7 +62,8 @@ void TPrintwin::paint_background(long j)
x1 = (unsigned char)rwd[cnt++]-1; x1 = (unsigned char)rwd[cnt++]-1;
x2 = (unsigned char)rwd[cnt++]-1; x2 = (unsigned char)rwd[cnt++]-1;
b.v = e.v = rw*_chary + _chary/2 + _vofs; b.v = e.v = rw*_chary + _chary/2 + _vofs;
b.h = x1*_charx+_charx/2 + _hofs; e.h = x2*_charx+_charx/2+_hofs; b.h = LEN_SPACES(x1)+LEN_SPACES(1)/2 + _hofs;
e.h = LEN_SPACES(x2)+LEN_SPACES(1)/2+_hofs;
win_move_to(win(),b); win_move_to(win(),b);
win_draw_line(win(),e); win_draw_line(win(),e);
break; break;
@ -88,11 +97,18 @@ void TPrintwin::paint_background(long j)
void TPrintwin::paint_row(long j) void TPrintwin::paint_row(long j)
{ {
static char line[257];
const char* cp; int pos = 0; const char* cp; int pos = 0;
int pixpos = 0;
int row = (int)(j % _formlen); int row = (int)(j % _formlen);
strcpy(line,_txt.line(j));
_txt.read_line(j); _txt.read_line(j);
while(cp = _txt.piece()) while(cp = _txt.piece())
{ {
pos += strlen(cp);
#if XVT_OS != XVT_OS_SCOUNIX #if XVT_OS != XVT_OS_SCOUNIX
int st = _txt.get_style(); int st = _txt.get_style();
long bg = trans_color(_txt.get_background()); long bg = trans_color(_txt.get_background());
@ -102,7 +118,7 @@ void TPrintwin::paint_row(long j)
#else #else
set_color(COLOR_BLACK, COLOR_WHITE); set_color(COLOR_BLACK, COLOR_WHITE);
#endif #endif
win_draw_text(win(), pos*_charx + _hofs, row*_chary + _chary + _vofs - _descent, win_draw_text(win(), pixpos+_hofs, row*_chary + _chary + _vofs - _descent,
(char *)cp, -1); (char *)cp, -1);
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
if (st & underlined) if (st & underlined)
@ -110,13 +126,13 @@ void TPrintwin::paint_row(long j)
PNT b, e; PNT b, e;
set_pen(COLOR_BLACK); set_pen(COLOR_BLACK);
b.h = _charx*pos + _hofs; b.v = row*_chary + _chary + _vofs; b.h = pixpos + _hofs; b.v = row*_chary + _chary + _vofs;
e.h = _charx*(pos+strlen(cp)) + _hofs; e.v = b.v; e.h = (pixpos+win_get_text_width(win(), line, pos)) + _hofs; e.v = b.v;
win_move_to (win(),b); win_move_to (win(),b);
win_draw_line(win(),e); win_draw_line(win(),e);
} }
#endif #endif
pos += strlen(cp); pixpos = win_get_text_width(win(), line, pos);
} }
paint_background(j); paint_background(j);
} }
@ -158,16 +174,17 @@ bool TPrintwin::do_print()
TPrintwin::~TPrintwin() TPrintwin::~TPrintwin()
{ {
close_print_window(win(), _printrcd); if (_inited && win() != NULL_WIN) close_print_window(win(), _printrcd);
set_win(NULL_WIN); set_win(NULL_WIN);
} }
TPrintwin::TPrintwin(PRINT_RCD* p, TTextfile& txt, int chsz) : TPrintwin::TPrintwin(PRINT_RCD* p, TTextfile& txt, int chsz) :
_printrcd(p), _aborted(FALSE), _txt(txt), _char_size(chsz) _printrcd(p), _aborted(FALSE), _txt(txt), _char_size(chsz), _inited(FALSE)
{ {
WINDOW w = new_print_window(_printrcd, (char*)(const char*)main_app().title()); WINDOW w = new_print_window(_printrcd, (char*)(const char*)main_app().title());
set_win(w); set_win(w);
_inited = TRUE;
if (w != NULL_WIN) if (w != NULL_WIN)
{ {
_bg = main_app().printer().getbgdesc(); _bg = main_app().printer().getbgdesc();
@ -177,13 +194,13 @@ _printrcd(p), _aborted(FALSE), _txt(txt), _char_size(chsz)
set_font(FF_SYSTEM,0,_char_size); set_font(FF_SYSTEM,0,_char_size);
win_get_font_metrics(win(), &_lead, &_ascent, &_descent); win_get_font_metrics(win(), &_lead, &_ascent, &_descent);
_charx = win_get_text_width(win(), "MM", -1) - win_get_text_width(win(), "M", -1);
_chary = main_app().printer().get_dots_per_line(); _chary = main_app().printer().get_dots_per_line();
RCT rct; get_client_rect(win(),&rct); RCT rct; get_client_rect(win(),&rct);
_vofs = main_app().printer().get_vert_offset(); _vofs = main_app().printer().get_vert_offset();
_hofs = (rct.right - rct.left) % _charx; _hofs = (rct.right - rct.left) % LEN_SPACES(1);
} }
else _aborted = TRUE; else _aborted = TRUE;
} }

View File

@ -26,8 +26,9 @@ class TPrintwin : public TWindow
int _lead, _ascent, _descent; int _lead, _ascent, _descent;
int _hofs, _vofs; int _hofs, _vofs;
int _charx, _chary; int _chary;
int _char_size; int _char_size;
bool _inited;
void paint_background(long j); void paint_background(long j);
void paint_row(long j); void paint_row(long j);

View File

@ -6,11 +6,11 @@ static char mytmpstr[257];
class _HotSpot : public TObject class _HotSpot : public TObject
{ {
public: public:
// TArray _spots; // tokenstrings // TArray _spots; // tokenstrings
char _bg, _fg; char _bg, _fg;
_HotSpot (char fg, char bg) _HotSpot (char fg, char bg)
{ {
_fg = fg; _fg = fg;
_bg = bg; _bg = bg;
@ -29,45 +29,45 @@ void TTextfile::set_hotspots (char fg, char bg)
style TTextfile::_trans_style (char ch) style TTextfile::_trans_style (char ch)
{ {
switch (ch) switch (ch)
{ {
case 'r': case 'r':
return normal; return normal;
break; break;
case 'i': case 'i':
return italic; return italic;
break; break;
case 'b': case 'b':
return bold; return bold;
break; break;
case 'u': case 'u':
return underlined; return underlined;
break; break;
case 'o': case 'o':
return overstrike; return overstrike;
break; break;
case 'k': case 'k':
return smallcaps; return smallcaps;
break; break;
default: default:
return normal; return normal;
break; break;
} }
} }
void TTextfile::_read_page (long n) void TTextfile::_read_page (long n)
{ {
switch (_direction) switch (_direction)
{ {
case down: case down:
_page_start = n; _page_start = n;
break; break;
case up: case up:
_page_start = n + _page_size; _page_start = n + _page_size;
break; break;
case updown: case updown:
_page_start = n - (_page_size / 2l); _page_start = n - (_page_size / 2l);
break; break;
} }
if (_page_start < 0l) if (_page_start < 0l)
_page_start = 0l; _page_start = 0l;
@ -86,40 +86,40 @@ void TTextfile::_read_page (long n)
fseek (_instr, l, SEEK_SET); fseek (_instr, l, SEEK_SET);
for (long i = _page_start; i <= _page_end; i++) for (long i = _page_start; i <= _page_end; i++)
{
if (feof (_instr))
break;
fgets (mytmpstr, sizeof (mytmpstr), _instr);
mytmpstr[strlen (mytmpstr) - 1] = '\0';
TString & ts = (TString &) _page[(int) (i - _page_start)];
ts = mytmpstr;
TString hcol (6);
// find hotspots and compile list
int len = 0;
const char *cp;
read_line (i, 0, FALSE);
while (cp = piece ())
{ {
if (feof (_instr)) for (int z = 0; z < _hotspots.items (); z++)
break; {
fgets (mytmpstr, sizeof (mytmpstr), _instr); _HotSpot & hs = (_HotSpot &) _hotspots[z];
mytmpstr[strlen (mytmpstr) - 1] = '\0'; if (hs._fg == get_foreground () && hs._bg == get_background ())
TString & ts = (TString &) _page[(int) (i - _page_start)];
ts = mytmpstr;
TString hcol (6);
// find hotspots and compile list
int len = 0;
const char *cp;
read_line (i, 0, FALSE);
while (cp = piece ())
{ {
for (int z = 0; z < _hotspots.items (); z++) TToken_string *tts = new TToken_string (50);
{ tts->add (i); // line number
_HotSpot & hs = (_HotSpot &) _hotspots[z];
if (hs._fg == get_foreground () && hs._bg == get_background ())
{
TToken_string *tts = new TToken_string (50);
tts->add (i); // line number
tts->add (len); tts->add (len);
tts->add (len + (int) strlen (cp)); tts->add (len + (int) strlen (cp));
tts->add (cp); tts->add (cp);
tts->add (z); tts->add (z);
_spots.add (tts); _spots.add (tts);
break; break;
}
}
len += strlen (cp);
} }
}
len += strlen (cp);
} }
}
} }
void TTextfile::read_line (long n, long pos, bool pg) void TTextfile::read_line (long n, long pos, bool pg)
@ -146,54 +146,54 @@ void TTextfile::read_line (long n, long pos, bool pg)
long stl = (long) col << 16; long stl = (long) col << 16;
while (ch = *sp++) while (ch = *sp++)
{
if (ch == '@' || (ch == '$' && *(sp) == '['))
{ {
if (ch == '@' || (ch == '$' && *(sp) == '[')) if (!first && p >= pos)
{ {
if (!first && p >= pos) _styles[_item++] = stl;
{ mytmpstr[ndx] = '\0';
_styles[_item++] = stl; _line.add (mytmpstr);
mytmpstr[ndx] = '\0'; ndx = 0;
_line.add (mytmpstr); }
ndx = 0; while (ch && (ch == '@' || (ch == '$' && *sp == '[')))
} {
while (ch && (ch == '@' || (ch == '$' && *sp == '['))) if (ch == '@') // font style change ?
{
if (ch == '@') // font style change ?
{ {
style sss = _trans_style (*sp++); style sss = _trans_style (*sp++);
if (sss == normal) if (sss == normal)
stl = (long) col << 16; stl = (long) col << 16;
else else
stl |= (long) sss; stl |= (long) sss;
} }
else if (ch == '$' && *sp == '[') // color change else if (ch == '$' && *sp == '[') // color change
{ {
++sp; // eat '[' ++sp; // eat '['
col = *sp++; col = *sp++;
++sp; // eat ',' ++sp; // eat ','
col |= ((int) (*sp++) << 8); col |= ((int) (*sp++) << 8);
++sp; // eat ']' ++sp; // eat ']'
stl = (stl & 0x0000ffff) | ((long) col << 16); stl = (stl & 0x0000ffff) | ((long) col << 16);
} }
ch = *sp++; ch = *sp++;
} // while } // while
}
if (ch && p >= pos)
{
first = FALSE;
mytmpstr[ndx++] = ch;
}
p++;
} }
if (ch && p >= pos)
{
first = FALSE;
mytmpstr[ndx++] = ch;
}
p++;
}
_styles[_item++] = stl; _styles[_item++] = stl;
mytmpstr[ndx] = '\0'; mytmpstr[ndx] = '\0';
_line.add (mytmpstr); _line.add(mytmpstr);
_item = 0; _item = 0;
} }
@ -212,23 +212,23 @@ long TTextfile::get_attribute (int pos)
{ {
long stl = 0; long stl = 0;
if (pos == -1) if (pos == -1)
{ {
CHECK (_item > 0, "must execute piece() before style()!"); CHECK (_item > 0, "must execute piece() before style()!");
stl = _styles[_item - 1]; stl = _styles[_item - 1];
} }
else else
{
int x = 0, nd = 0;
const char *c;
_line.restart ();
while (c = _line.get ())
{ {
int x = 0, nd = 0; x += strlen (c);
const char *c; stl = _styles[nd++];
_line.restart (); if ((x - 1) >= pos)
while (c = _line.get ()) break;
{
x += strlen (c);
stl = _styles[nd++];
if ((x - 1) >= pos)
break;
}
} }
}
return stl; return stl;
} }
@ -264,22 +264,22 @@ const char *TTextfile::word_at (long x, long y)
int x2 = 0; int x2 = 0;
if (x < s.len ()) if (x < s.len ())
{
while (isspace (s[(int) x]))
{ {
while (isspace (s[(int) x])) if (x == (s.len () - 1) && y < (_lines - 1l))
{ {
if (x == (s.len () - 1) && y < (_lines - 1l)) s = line (++y);
{ x = 0l;
s = line (++y); }
x = 0l; else if (x < (s.len () - 1))
} x++;
else if (x < (s.len () - 1)) else
x++; break;
else
break;
}
while (isalnum (s[(int) x]))
mytmpstr[x2++] = s[(int) x++];
} }
while (isalnum (s[(int) x]))
mytmpstr[x2++] = s[(int) x++];
}
mytmpstr[x2] = '\0'; mytmpstr[x2] = '\0';
return mytmpstr; return mytmpstr;
} }
@ -297,10 +297,10 @@ bool TTextfile::append (const char *l)
fprintf (_instr, "%s\n", l); fprintf (_instr, "%s\n", l);
fwrite (&cpos, sizeof (long), 1, _index); fwrite (&cpos, sizeof (long), 1, _index);
if (ferror (_index) || ferror (_instr)) if (ferror (_index) || ferror (_instr))
{ {
error_box ("Errore di scrittura file temporaneo: scrittura interrotta"); error_box ("Errore di scrittura file temporaneo: scrittura interrotta");
freeze (); freeze ();
} }
fflush (_index); fflush (_index);
fflush (_instr); fflush (_instr);
@ -308,37 +308,37 @@ bool TTextfile::append (const char *l)
_dirty = TRUE; _dirty = TRUE;
if ((_lines) < (_page_start + _page_size)) if ((_lines) < (_page_start + _page_size))
{
TString *ll = new TString (l);
_page.add (ll);
_page_end++;
int len = 0;
const char *cp;
read_line (_lines - 1);
while (cp = piece ())
{ {
TString *ll = new TString (l); for (int z = 0; z < _hotspots.items (); z++)
_page.add (ll); {
_page_end++; _HotSpot & hs = (_HotSpot &) _hotspots[z];
if (hs._fg == get_foreground () && hs._bg == get_background ())
{
TToken_string *tts = new TToken_string (50);
tts->add (_lines - 1l); // line number
//
int len = 0; tts->add (len);
const char *cp; tts->add (len + (int) strlen (cp));
read_line (_lines - 1); tts->add (cp);
while (cp = piece ()) tts->add (z);
{ _spots.add (tts);
for (int z = 0; z < _hotspots.items (); z++) break;
{ }
_HotSpot & hs = (_HotSpot &) _hotspots[z]; }
if (hs._fg == get_foreground () && hs._bg == get_background ()) len += strlen (cp);
{
TToken_string *tts = new TToken_string (50);
tts->add (_lines - 1l); // line number
//
tts->add (len);
tts->add (len + (int) strlen (cp));
tts->add (cp);
tts->add (z);
_spots.add (tts);
break;
}
}
len += strlen (cp);
}
return TRUE;
} }
return TRUE;
}
return FALSE; return FALSE;
} }
@ -365,30 +365,30 @@ bool TTextfile::write (const char *path, TPoint * from, TPoint * to)
bool ok = FALSE; bool ok = FALSE;
FILE *fp; FILE *fp;
if ((fp = fopen (path, "w")) != NULL) if ((fp = fopen (path, "w")) != NULL)
{
ok = TRUE;
TString256 s;
long starty = from == NULL ? 0l : from->y;
int startx = from == NULL ? 0 : (int) from->x;
long endy = to == NULL ? _lines - 1l : to->y;
int endx = to == NULL ? -1 : (int) to->x;
for (long j = starty; j <= endy; j++)
{ {
ok = TRUE; s = line (j);
TString256 s; if (j == endy && endx == -1)
long starty = from == NULL ? 0l : from->y; endx = s.len ();
int startx = from == NULL ? 0 : (int) from->x;
long endy = to == NULL ? _lines - 1l : to->y;
int endx = to == NULL ? -1 : (int) to->x;
for (long j = starty; j <= endy; j++)
{
s = line (j);
if (j == endy && endx == -1)
endx = s.len ();
if (j == starty && j == endy) if (j == starty && j == endy)
s = s.sub (startx, endx); s = s.sub (startx, endx);
else if (j == starty) else if (j == starty)
s = s.mid (startx); s = s.mid (startx);
else if (j == endy) else if (j == endy)
s = s.left (endx); s = s.left (endx);
fprintf (fp, "%s\n", (const char *) s); fprintf (fp, "%s\n", (const char *) s);
}
fclose (fp);
} }
fclose (fp);
}
else else
warning_box ("Impossibile scrivere il file %s; scrittura fallita", path); warning_box ("Impossibile scrivere il file %s; scrittura fallita", path);
return ok; return ok;
@ -398,65 +398,65 @@ void TTextfile::destroy ()
{ {
CHECK (_istemp, "destroy() chiamata su testo permanente!"); CHECK (_istemp, "destroy() chiamata su testo permanente!");
if (_page.items () > 0) if (_page.items () > 0)
{
if (_index)
fclose (_index);
if (_instr)
fclose (_instr);
remove ((const char *) _filename);
remove ((const char *) _indname);
_page_start = _lines = 0l;
_page_end = _cur_line = -1l;
_accept = TRUE;
_instr = fopen (_filename, "a+");
_indname.temp ();
_index = fopen (_indname, "w+b");
if (_index == NULL || _instr == NULL)
{ {
if (_index) error_box ("Impossibile aprire files temporanei");
fclose (_index); freeze ();
if (_instr)
fclose (_instr);
remove ((const char *) _filename);
remove ((const char *) _indname);
_page_start = _lines = 0l;
_page_end = _cur_line = -1l;
_accept = TRUE;
_instr = fopen (_filename, "a+");
_indname.temp ();
_index = fopen (_indname, "w+b");
if (_index == NULL || _instr == NULL)
{
error_box ("Impossibile aprire files temporanei");
freeze ();
}
_isopen = TRUE;
_page.destroy ();
_spots.destroy ();
} }
_isopen = TRUE;
_page.destroy ();
_spots.destroy ();
}
} }
TTextfile ::TTextfile (const char *file, int pagesize, direction preferred): TTextfile ::TTextfile (const char *file, int pagesize, direction preferred):
_page_size (pagesize), _page (pagesize), _filename (file), _lines (0l), _page_size (pagesize), _page (pagesize), _filename (file), _lines (0l),
_index (NULL), _page_start (0l), _page_end (-1l), _direction (preferred), _index (NULL), _page_start (0l), _page_end (-1l), _direction (preferred),
_dirty (FALSE), _istemp (FALSE), _item (0), _line (256), _cur_line (-1), _dirty (FALSE), _istemp (FALSE), _item (0), _line (256), _cur_line (-1),
_hotspots (4), _accept (TRUE) _hotspots (4), _accept (TRUE)
{ {
// open file & build index // open file & build index
if (file == NULL) if (file == NULL)
{ {
_filename.temp (); _filename.temp ();
_istemp = TRUE; _istemp = TRUE;
} }
_instr = fopen (_filename, "a+"); _instr = fopen (_filename, "a+");
_indname.temp (); _indname.temp ();
_index = fopen (_indname, "w+b"); _index = fopen (_indname, "w+b");
if (_index == NULL || _instr == NULL) if (_index == NULL || _instr == NULL)
{ {
error_box ("Impossibile aprire files temporanei"); error_box ("Impossibile aprire files temporanei");
freeze (); freeze ();
} }
if (file != NULL) if (file != NULL)
while (!feof (_instr)) while (!feof (_instr))
{
const long l = ftell (_instr);
fwrite (&l, sizeof (long), 1, _index);
if (ferror (_index) || ferror (_instr))
{ {
const long l = ftell (_instr); error_box ("Errore di scrittura file temporaneo: scrittura interrotta");
fwrite (&l, sizeof (long), 1, _index); freeze ();
if (ferror (_index) || ferror (_instr))
{
error_box ("Errore di scrittura file temporaneo: scrittura interrotta");
freeze ();
}
fgets (mytmpstr, sizeof (mytmpstr), _instr);
_lines++;
} }
fgets (mytmpstr, sizeof (mytmpstr), _instr);
_lines++;
}
_isopen = TRUE; _isopen = TRUE;
} }