Aggiunta gestione posizioni di tabulazione per stampe con caratteri

proporzionali.
Gestione configurazioni di stampa applicazione per applicazione se
necessaria.


git-svn-id: svn://10.65.10.50/trunk@1360 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1995-05-12 09:24:47 +00:00
parent ed528194e8
commit 6f0963cb41
8 changed files with 235 additions and 143 deletions

View File

@ -286,6 +286,7 @@ TConfig::TConfig(int which_config, const char* paragraph)
_file = "prassis.ini"; _file = "prassis.ini";
break; break;
case CONFIG_USER: case CONFIG_USER:
case CONFIG_STAMPE:
_file = main_app().get_firm_dir(); _file = main_app().get_firm_dir();
if (_file.not_empty()) if (_file.not_empty())
{ {
@ -296,7 +297,7 @@ TConfig::TConfig(int which_config, const char* paragraph)
_file << "config"; _file << "config";
if (!fexist(_file)) if (!fexist(_file))
make_dir(_file); make_dir(_file);
_file << '/' << user() << ".ini"; _file << '/' << (which_config == CONFIG_USER ? user() : "print") << ".ini";
break; break;
case CONFIG_FCONV: case CONFIG_FCONV:
_file = "fconv.ini"; _file = "fconv.ini";
@ -306,13 +307,6 @@ TConfig::TConfig(int which_config, const char* paragraph)
break; break;
} }
if (!fexist(_file))
{
FILE* c = fopen(_file, "w");
CHECKS(c, "Impossibile aprire il file di configurazione %s", (const char*)_file);
fclose(c);
}
init(_file, paragraph); init(_file, paragraph);
} }

View File

@ -21,7 +21,8 @@ class ofstream;
#define CONFIG_FCONV 3 #define CONFIG_FCONV 3
// file parametri utente // file parametri utente
#define CONFIG_USER 4 #define CONFIG_USER 4
// file parametri stampe
#define CONFIG_STAMPE 5
class TConfig : public TObject class TConfig : public TObject
{ {

View File

@ -1,7 +1,7 @@
#ifndef APPNAME #ifndef APPNAME
#define APPNAME PRASSI #define APPNAME PRASSI
#define QAPPNAME "PRASSI" #define QAPPNAME "PRASSI"
#define LIBDIR f:\xvt.45b\w16_x86\ptk\lib #define LIBDIR f:\xvt.403\win_x86\ptk\lib
#endif #endif
#define NO_STD_EDIT_MENU #define NO_STD_EDIT_MENU

View File

@ -443,13 +443,18 @@ word TPrintrow::class_id()
TPrintrow & TPrintrow::reset () TPrintrow & TPrintrow::reset ()
{ {
_row.spaces (sizeof (_attr)); _row.spaces (sizeof (_attr)); // Azzera testo
memset (_attr, normalstyle, sizeof (_attr)); // Azzera stile
_tab.reset(); // Azzera tabulazioni
_currentcolor = 'w'; _currentcolor = 'w';
_currentcolor <<= 8; _currentcolor <<= 8;
_currentcolor += 'n'; _currentcolor += 'n';
memset (_attr, normalstyle, sizeof (_attr));
for (int i = 0; i < MAXSTR; i++) for (int i = 0; i < MAXSTR; i++)
_cols[i] = _currentcolor; _cols[i] = _currentcolor; // Azzera colori
_lastpos = 0; _lastpos = 0;
_currentstyle = normalstyle; _currentstyle = normalstyle;
return *this; return *this;
@ -467,6 +472,12 @@ const char* TPrintrow::row_codified() const
for (i = 0; i < _row.size(); i++) for (i = 0; i < _row.size(); i++)
{ {
if (_tab[i])
{
__tmp_string[k++] = '@';
__tmp_string[k++] = 't';
}
if (_attr[i] != last_attr) if (_attr[i] != last_attr)
{ {
__tmp_string[k++] = '@'; __tmp_string[k++] = '@';
@ -510,12 +521,10 @@ TPrintrow & TPrintrow::put(const char *str, int position, int len)
if (len < 1) if (len < 1)
len = strlen (str); len = strlen (str);
bool jumped = TRUE;
if (position < 0) if (position < 0)
{
position = _lastpos; position = _lastpos;
jumped = FALSE; else
} _tab.set(position);
char bg = 'w', fg = 'n'; char bg = 'w', fg = 'n';
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
@ -594,6 +603,7 @@ TPrintrow & TPrintrow::put(const char *str, int position, int len)
_cols[k] = _currentcolor; _cols[k] = _currentcolor;
} }
position = pp; position = pp;
_tab.set(position);
} }
else if (toupper (c) == 'J') else if (toupper (c) == 'J')
{ {
@ -605,6 +615,7 @@ TPrintrow & TPrintrow::put(const char *str, int position, int len)
_cols[k + position] = _currentcolor; _cols[k + position] = _currentcolor;
} }
position += pp; position += pp;
_tab.set(position);
} }
} }
else else
@ -705,8 +716,11 @@ HIDDEN bool set_windows_print_device (TMask_field& f, KEY key)
{ {
if (key == K_SPACE) if (key == K_SPACE)
{ {
main_app().begin_wait();
TPrinter& pr = printer(); TPrinter& pr = printer();
if (f.dirty())
{
TToken_string& pn = pr.getprinternames (); TToken_string& pn = pr.getprinternames ();
TString80 pdev (pn.get(atoi (f.get()))); // Nome stampante corrente TString80 pdev (pn.get(atoi (f.get()))); // Nome stampante corrente
@ -718,22 +732,36 @@ HIDDEN bool set_windows_print_device (TMask_field& f, KEY key)
WriteProfileString("windows", "device", pdev); WriteProfileString("windows", "device", pdev);
pr.set_printrcd(); pr.set_printrcd();
pr.set_win_formlen(); pr.set_win_formlen();
}
const int MAX_FAMILIES = 128; const int MAX_FAMILIES = 128;
char* family[MAX_FAMILIES]; char* family[MAX_FAMILIES];
const int num_families = (int)xvt_fmap_get_families(pr.get_printrcd(), family, MAX_FAMILIES); const int num_families = (int)xvt_fmap_get_families(pr.get_printrcd(), family, MAX_FAMILIES);
TToken_string pn1(256), pn2(256); TToken_string pn1(256), pn2(256);
const int MAXSIZES = 16;
long sizes[MAXSIZES];
BOOLEAN scalable;
for (int i = 0; i < num_families; i++) for (int i = 0; i < num_families; i++)
{
const int num_sizes = (int)xvt_fmap_get_family_sizes(pr.get_printrcd(),
family[i], sizes, &scalable, MAXSIZES);
if (num_sizes > 0)
{ {
pn1.add(family[i]); pn1.add(family[i]);
pn2.add(family[i]); pn2.add(family[i]);
} }
xvt_mem_free(family[i]);
}
TMask& m = f.mask(); TMask& m = f.mask();
TList_field& lst = (TList_field&)m.field(MSK_1_FONT); TList_field& lst = (TList_field&)m.field(MSK_1_FONT);
lst.replace_items(pn1, pn2); lst.replace_items(pn1, pn2);
lst.set(printer().fontname()); lst.set(printer().fontname());
main_app().end_wait();
} }
return TRUE; return TRUE;
} }
@ -742,8 +770,10 @@ HIDDEN bool font_handler(TMask_field& f, KEY key)
{ {
if (key == K_SPACE) if (key == K_SPACE)
{ {
main_app().begin_wait();
const char* family = f.get(); const char* family = f.get();
const int MAXSIZES = 32; const int MAXSIZES = 16;
long sizes[MAXSIZES]; long sizes[MAXSIZES];
BOOLEAN scalable; BOOLEAN scalable;
const int num_sizes = (int)xvt_fmap_get_family_sizes(printer().get_printrcd(), const int num_sizes = (int)xvt_fmap_get_family_sizes(printer().get_printrcd(),
@ -765,9 +795,10 @@ HIDDEN bool font_handler(TMask_field& f, KEY key)
} }
TList_field& lst = (TList_field&)f.mask().field(MSK_1_SIZE); TList_field& lst = (TList_field&)f.mask().field(MSK_1_SIZE);
const TString16 old(lst.get());
lst.replace_items(pn1, pn2); lst.replace_items(pn1, pn2);
lst.set(old); lst.set(format("%d", printer().get_char_size()));
main_app().end_wait();
} }
return TRUE; return TRUE;
} }
@ -837,8 +868,10 @@ TToken_string& TPrinter::getprinternames ()
return _printer_names; return _printer_names;
} }
void TPrinter::read_configuration() void TPrinter::read_configuration(const char* parag)
{ {
main_app().begin_wait();
#if XVT_OS == XVT_OS_SCOUNIX #if XVT_OS == XVT_OS_SCOUNIX
const char* const config = "printer.ini"; const char* const config = "printer.ini";
FILE *cnfp = fopen (config, "r"); FILE *cnfp = fopen (config, "r");
@ -874,16 +907,46 @@ void TPrinter::read_configuration()
#endif #endif
TConfig prini(CONFIG_USER, "Printer"); _config = parag;
if (_config.empty())
_config = "Printer";
const int what = prini.get_int("Type", NULL, -1, 0); // Tipo stampante TConfig* iniptr = NULL;
_curprn = prini.get_int("Number", NULL, -1, 0); // Numero stampante corrente if (_config != "Printer")
_printerfile = prini.get("File", NULL, -1, ""); // File di stampa {
_curcode = prini.get_int("Codes", NULL, -1, 0); // Codici di stampa iniptr = new TConfig(CONFIG_STAMPE, _config);
_fontname = prini.get("Font", NULL, -1, XVT_FFN_FIXED); // Nome del font if (!iniptr->exist("Type"))
_ch_size = prini.get_int("Size", NULL, -1, 12); // Dimensione del font {
_lines_per_inch = prini.get_int("Lines", NULL, -1, 6); // Linee per pollice delete iniptr; iniptr = NULL;
_isgraphics = prini.get_bool("Graphic", NULL, -1, FALSE); // Grafica attiva }
}
if (iniptr == NULL)
iniptr = new TConfig(CONFIG_USER, "Printer");
const int what = iniptr->get_int("Type", NULL, -1, 0); // Tipo stampante
_curprn = iniptr->get_int("Number", NULL, -1, 0); // Numero stampante corrente
_printerfile = iniptr->get("File", NULL, -1, ""); // File di stampa
_curcode = iniptr->get_int("Codes", NULL, -1, 0); // Codici di stampa
_fontname = iniptr->get("Font", NULL, -1, XVT_FFN_FIXED); // Nome del font
_ch_size = iniptr->get_int("Size", NULL, -1, 12); // Dimensione del font
_lines_per_inch = iniptr->get_int("Lines", NULL, -1, 6); // Linee per pollice
_isgraphics = iniptr->get_bool("Graphic", NULL, -1, FALSE); // Grafica attiva
if (iniptr->exist("rcd", 0))
{
int size, i = 0;
byte* rcd = (byte*)get_printrcd(&size);
TToken_string s(256);
for (int index = 0; i < size; index++)
{
s = iniptr->get("rcd", NULL, index);
for (const char* n = s.get(0); n; n = s.get())
rcd[i++] = (byte)atoi(n);
}
}
delete iniptr; iniptr = NULL;
if (_printerfile.empty()) if (_printerfile.empty())
{ {
@ -898,6 +961,7 @@ void TPrinter::read_configuration()
switch (what) switch (what)
{ {
case 0: case 0:
case 5:
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
_printertype = winprinter; _printertype = winprinter;
#else #else
@ -926,6 +990,47 @@ void TPrinter::read_configuration()
default: default:
break; break;
} }
main_app().end_wait();
}
void TPrinter::save_configuration()
{
main_app().begin_wait();
CHECK(_config.not_empty(), "Invalid printer config");
TConfig prini(_config == "Printer" ? CONFIG_USER : CONFIG_STAMPE, _config);
prini.set("Type", _printertype); // Tipo stampante
prini.set("Number", _curprn); // Numero stampante corrente
prini.set("File", _printerfile); // File di stampa
prini.set("Codes", _curcode); // Codici di stampa
prini.set("Font", _fontname); // Nome del font
prini.set("Size", _ch_size); // Dimensione del font
prini.set("Lines", _lines_per_inch); // Linee per pollice
prini.set("Graphic", _isgraphics ? "X" : ""); // Grafica attiva
int n = 0, index = 0;
TToken_string val(256);
int rcdsize;
byte* rcd = (byte*)get_printrcd(&rcdsize);
for (int i = 0; i < rcdsize; i++)
{
val.add((int)rcd[i]);
n++;
if (n == 24)
{
prini.set("rcd", val, NULL, TRUE, index++);
val.cut(n = 0);
}
}
if (n > 0)
prini.set("rcd", val, NULL, TRUE, index);
main_app().end_wait();
} }
TPrinter::~TPrinter () TPrinter::~TPrinter ()
@ -1305,6 +1410,7 @@ void TPrinter::set()
mask.set(MSK_1_FILENAME, _printerfile); mask.set(MSK_1_FILENAME, _printerfile);
mask.set(MSK_1_NPAGES, _ncopies); mask.set(MSK_1_NPAGES, _ncopies);
mask.enable(DLG_OK, _config == "Printer");
#if XVT_OS == XVT_OS_SCOUNIX #if XVT_OS == XVT_OS_SCOUNIX
@ -1343,13 +1449,9 @@ void TPrinter::set()
mask.show(MSK_1_CODES); mask.show(MSK_1_CODES);
mask.set(MSK_1_CODES, _curcode); mask.set(MSK_1_CODES, _curcode);
KEY k; KEY k = mask.run();
if ((k = mask.run()) == K_ESC) if (k == K_ESC) return;
return;
if (k == K_INS) // premuto REGISTRA
mask.save();
// get user choices // get user choices
@ -1436,8 +1538,7 @@ void TPrinter::set()
_curprn = pn2.get_pos(name); _curprn = pn2.get_pos(name);
CHECKS(_curprn >= 0, "Can't find printer ", name); CHECKS(_curprn >= 0, "Can't find printer ", name);
mask.set(MSK_1_PRINTERS, pn1.get(_curprn)); mask.set(MSK_1_PRINTERS, pn1.get(_curprn));
// set_win_formlen(); // Update dimensions
set_win_formlen(); // Update dimensions
} }
else else
beep (); beep ();
@ -1487,21 +1588,11 @@ void TPrinter::set()
_isgraphics = mask.get_bool (MSK_1_ISGRAPHICS); _isgraphics = mask.get_bool (MSK_1_ISGRAPHICS);
set_win_formlen (); set_win_formlen ();
if (k == K_INS)
{
TConfig prini(CONFIG_USER, "Printer");
prini.set("Type", _printertype); // Tipo stampante
prini.set("Number", _curprn); // Numero stampante corrente
prini.set("File", _printerfile); // File di stampa
prini.set("Codes", _curcode); // Codici di stampa
prini.set("Font", _fontname); // Nome del font
prini.set("Size", _ch_size); // Dimensione del font
prini.set("Lines", _lines_per_inch); // Linee per pollice
prini.set("Graphic", _isgraphics ? "X" : ""); // Grafica attiva
}
#endif #endif
if (k == K_INS)
save_configuration();
main_app().enable_menu_item (M_FILE_PG_SETUP); main_app().enable_menu_item (M_FILE_PG_SETUP);
} }
@ -1635,14 +1726,13 @@ _isopen = FALSE;
#include <bagn004.h> #include <bagn004.h>
#if XVT_OS == XVT_OS_DOS #if XVT_OS == XVT_OS_WIN
#define FORMAT_COMMAND "FORMAT" const char* const FORMAT_COMMAND = "FORMAT";
#else #else
#define FORMAT_COMMAND "dosformat -fq" const char* const FORMAT_COMMAND = "dosformat -fq";
#endif #endif
const long disk_sizes[] = const long disk_sizes[] = { 360000L, 1200000L, 720000L, 1400000L, 2880000L };
{360000, 1200000, 720000, 1400000, 2880000};
TFile_printer::TFile_printer (const char *ffile, const char *label, int len_rec, int num_rec_inizio, int num_rec_fine, int tipo_disco) TFile_printer::TFile_printer (const char *ffile, const char *label, int len_rec, int num_rec_inizio, int num_rec_fine, int tipo_disco)
{ {

View File

@ -20,11 +20,11 @@ enum TPrintstyle
normalstyle = 0, normalstyle = 0,
boldstyle = 1, boldstyle = 1,
underlinedstyle = 2, underlinedstyle = 2,
italicstyle = 4, italicstyle = 4
jumpstyle = 64
}; };
enum TPrtype { enum TPrtype
{
normprinter = 0, normprinter = 0,
fileprinter = 1, fileprinter = 1,
spoolprinter = 2, spoolprinter = 2,
@ -49,6 +49,8 @@ class TPrintrow : public TObject
TString256 _row; // the actual string to print TString256 _row; // the actual string to print
char _attr[MAXSTR]; // contains char attributes of _row char _attr[MAXSTR]; // contains char attributes of _row
int _cols[MAXSTR]; // contains color attributes of _row int _cols[MAXSTR]; // contains color attributes of _row
TBit_array _tab;
TPrintstyle _currentstyle; // the current char attribute TPrintstyle _currentstyle; // the current char attribute
int _currentcolor; // the current color attribute int _currentcolor; // the current color attribute
int _lastpos; // last print position int _lastpos; // last print position
@ -160,6 +162,7 @@ class TPrinter : public TObject
TArray _bookmarks; // bookmarks TArray _bookmarks; // bookmarks
bool _multiple_link; // bool _multiple_link; //
TString _config; // Nome del paragrafo di configurazione
TString_array _background; TString_array _background;
TString_array _image_names; TString_array _image_names;
@ -193,11 +196,12 @@ protected:
virtual char newline() { return '\n'; } virtual char newline() { return '\n'; }
bool printrow (TPrintrow* rowtoprint=NULL); // base methods for printing bool printrow (TPrintrow* rowtoprint=NULL); // base methods for printing
bool printformfeed (); bool printformfeed ();
void read_configuration();
bool printheader(); bool printheader();
bool printfooter(); bool printfooter();
void save_configuration();
public: public:
// @FPUB // @FPUB
@ -309,6 +313,8 @@ public:
int get_char_size() const { return _ch_size; } int get_char_size() const { return _ch_size; }
char* fontname() const { return (char*)(const char*)_fontname; } char* fontname() const { return (char*)(const char*)_fontname; }
void read_configuration(const char* parag = NULL);
// bookmarks // bookmarks
int set_bookmark(const char* txt, int father = -1); int set_bookmark(const char* txt, int father = -1);
}; };

View File

@ -13,7 +13,7 @@ HIDDEN int LEN_SPACES(WINDOW win, int x)
} }
if (w == 0L) if (w == 0L)
{ {
TString256 spc; spc.fill('M', 132); TString256 spc; spc.fill('m', 132);
w = xvt_dwin_get_text_width(win,(char*)(const char*)spc, 132); w = xvt_dwin_get_text_width(win,(char*)(const char*)spc, 132);
} }
const int k = int((w*x) / 132); const int k = int((w*x) / 132);
@ -22,7 +22,7 @@ HIDDEN int LEN_SPACES(WINDOW win, int x)
static bool error_on = TRUE; static bool error_on = TRUE;
if (error_on) if (error_on)
{ {
TString256 spc; spc.fill('M', x); TString256 spc; spc.fill('m', x);
const int k1 = xvt_dwin_get_text_width(win,(char*)(const char*)spc,x); const int k1 = xvt_dwin_get_text_width(win,(char*)(const char*)spc,x);
if (k != k1) if (k != k1)
error_on = error_box("Maguire disagrees: %d != %d", k, k1); error_on = error_box("Maguire disagrees: %d != %d", k, k1);
@ -171,29 +171,27 @@ void TPrintwin::paint_row(long j)
while((cp = _txt.piece()) != NULL) while((cp = _txt.piece()) != NULL)
{ {
#if XVT_OS != XVT_OS_SCOUNIX #if XVT_OS != XVT_OS_SCOUNIX
int st = _txt.get_style(); const int st = _txt.get_style();
long bg = trans_color(_txt.get_background());
long fg = trans_color(_txt.get_foreground());
set_font(printer().fontname(), st, _char_size); set_font(printer().fontname(), st, _char_size);
const COLOR bg = trans_color(_txt.get_background());
const COLOR fg = trans_color(_txt.get_foreground());
set_color(fg, bg); set_color(fg, bg);
#else #else
set_color(COLOR_BLACK, COLOR_WHITE); set_color(COLOR_BLACK, COLOR_WHITE);
#endif #endif
const char* end = NULL; const char* beg = cp;
for (const char* begin = cp; *begin; begin = end) while (*beg)
{ {
for (; *begin == ' '; begin++)
pos++;
int len = 0; int len = 0;
for (end = begin; *end > ' ' || (*end && *(end+1) > ' '); end++) for (; *beg == ' '; beg++) // Salta spazi iniziali
len++; pos++;
for (const char* end = beg; *end > ' ' || (*end && *(end+1) > ' '); end++)
if (*begin > ' ') len++; // Misura sringa da stampare
xvt_dwin_draw_text(win(), _hofs + LEN_SPACES(win(), pos), y, (char*)begin, len); xvt_dwin_draw_text(win(), _hofs + LEN_SPACES(win(), pos), y, (char*)beg, len);
pos += len; pos += len;
beg = end;
} }
} }
} }

View File

@ -3,7 +3,7 @@
#include <ctype.h> #include <ctype.h>
#include <applicat.h> #include <applicat.h>
static char mytmpstr[257]; static char TEXT_TMP[257];
class _HotSpot : public TObject class _HotSpot : public TObject
{ {
@ -33,19 +33,16 @@ style TTextfile::_trans_style (char ch)
{ {
case 'r': case 'r':
return normal; return normal;
break;
case 'i': case 'i':
return italic; return italic;
break;
case 'b': case 'b':
return bold; return bold;
break;
case 'u': case 'u':
return underlined; return underlined;
break; case 't':
return tabbed;
default: default:
return normal; return normal;
break;
} }
} }
@ -84,7 +81,7 @@ void TTextfile::_save_changes()
freeze (); freeze ();
} }
if (fgets(mytmpstr, sizeof(mytmpstr), _instr) == NULL) if (fgets(TEXT_TMP, sizeof(TEXT_TMP), _instr) == NULL)
break; break;
if (line >= _page_start && line <= _page_end) if (line >= _page_start && line <= _page_end)
@ -92,12 +89,12 @@ void TTextfile::_save_changes()
TString& lin = (TString&)(_page[(int)(line - _page_start)]); TString& lin = (TString&)(_page[(int)(line - _page_start)]);
if (_dirty_lines[line - _page_start]) if (_dirty_lines[line - _page_start])
{ {
strcpy(mytmpstr, lin); strcpy(TEXT_TMP, lin);
strcat(mytmpstr, "\n"); strcat(TEXT_TMP, "\n");
} }
} }
fprintf(newf, "%s", mytmpstr); fprintf(newf, "%s", TEXT_TMP);
line++; line++;
} }
@ -153,10 +150,10 @@ void TTextfile::_read_page (long n)
{ {
if (feof (_instr)) if (feof (_instr))
break; break;
fgets (mytmpstr, sizeof (mytmpstr), _instr); fgets (TEXT_TMP, sizeof (TEXT_TMP), _instr);
mytmpstr[strlen (mytmpstr) - 1] = '\0'; TEXT_TMP[strlen (TEXT_TMP) - 1] = '\0';
TString & ts = (TString &) _page[(int) (i - _page_start)]; TString & ts = (TString &) _page[(int) (i - _page_start)];
ts = mytmpstr; ts = TEXT_TMP;
TString hcol (6); TString hcol (6);
// find hotspots and compile list // find hotspots and compile list
@ -216,16 +213,17 @@ void TTextfile::read_line (long n, long pos, bool pg)
if (!first && p >= pos) if (!first && p >= pos)
{ {
_styles[_item++] = stl; _styles[_item++] = stl;
mytmpstr[ndx] = '\0'; TEXT_TMP[ndx] = '\0';
_line.add (mytmpstr); _line.add (TEXT_TMP);
ndx = 0; 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++); const char c = *sp++;
style sss = _trans_style (c);
if (sss == normal) if (sss == normal)
stl = (long) col << 16; stl = (long) col << 16;
else else
@ -251,13 +249,13 @@ void TTextfile::read_line (long n, long pos, bool pg)
if (ch && p >= pos) if (ch && p >= pos)
{ {
first = FALSE; first = FALSE;
mytmpstr[ndx++] = ch; TEXT_TMP[ndx++] = ch;
} }
p++; p++;
} }
_styles[_item++] = stl; _styles[_item++] = stl;
mytmpstr[ndx] = '\0'; TEXT_TMP[ndx] = '\0';
_line.add(mytmpstr); _line.add(TEXT_TMP);
_item = 0; _item = 0;
} }
@ -265,16 +263,16 @@ const char *TTextfile::line(long j, long pos, int howmuch)
{ {
if (_cur_line != j) if (_cur_line != j)
read_line (j); read_line (j);
*mytmpstr = '\0'; *TEXT_TMP = '\0';
_line.restart (); _line.restart ();
for (int i = 0; i < _line.items (); i++) for (int i = 0; i < _line.items (); i++)
strcat (mytmpstr, (const char *) _line.get ()); strcat (TEXT_TMP, (const char *) _line.get ());
if (howmuch != -1) if (howmuch != -1)
{ {
if (((unsigned int)pos+howmuch) < strlen(mytmpstr)) if (((unsigned int)pos+howmuch) < strlen(TEXT_TMP))
mytmpstr[pos+howmuch] = '\0'; TEXT_TMP[pos+howmuch] = '\0';
} }
return strlen(mytmpstr) > (word)pos ? &(mytmpstr[pos]) : ""; return strlen(TEXT_TMP) > (word)pos ? &(TEXT_TMP[pos]) : "";
} }
@ -345,8 +343,8 @@ const char *TTextfile::line_formatted(long j)
if (_cur_line != j) if (_cur_line != j)
read_line (j); read_line (j);
TString* tp = (TString*)_page.objptr(int(j-_page_start)); TString* tp = (TString*)_page.objptr(int(j-_page_start));
strcpy(mytmpstr, (const char*)(*tp)); strcpy(TEXT_TMP, (const char*)(*tp));
return mytmpstr; return TEXT_TMP;
} }
long TTextfile::get_attribute (int pos) long TTextfile::get_attribute (int pos)
@ -362,7 +360,7 @@ long TTextfile::get_attribute (int pos)
int x = 0, nd = 0; int x = 0, nd = 0;
const char *c; const char *c;
_line.restart (); _line.restart ();
while (c = _line.get ()) while ((c = _line.get ()) != NULL)
{ {
x += strlen (c); x += strlen (c);
stl = _styles[nd++]; stl = _styles[nd++];
@ -375,7 +373,7 @@ long TTextfile::get_attribute (int pos)
int TTextfile::get_style (int pos) int TTextfile::get_style (int pos)
{ {
long x = get_attribute (pos); const long x = get_attribute(pos) & ~tabbed;
return (int) (x & 0x0000ffff); return (int) (x & 0x0000ffff);
} }
@ -393,9 +391,11 @@ char TTextfile::get_foreground (int pos)
const char* TTextfile::piece() const char* TTextfile::piece()
{ {
if (_item >= _line.items ()) const char* l = _line.get(_item);
if (l == NULL)
return NULL; return NULL;
return strcpy (mytmpstr, (const char *) _line.get (_item++)); _item++;
return strcpy(TEXT_TMP, l);
} }
const char *TTextfile::word_at (long x, long y) const char *TTextfile::word_at (long x, long y)
@ -419,10 +419,10 @@ const char *TTextfile::word_at (long x, long y)
break; break;
} }
while (isalnum (s[(int) x])) while (isalnum (s[(int) x]))
mytmpstr[x2++] = s[(int) x++]; TEXT_TMP[x2++] = s[(int) x++];
} }
mytmpstr[x2] = '\0'; TEXT_TMP[x2] = '\0';
return mytmpstr; return TEXT_TMP;
} }
bool TTextfile::append (const char *l) bool TTextfile::append (const char *l)
@ -596,13 +596,13 @@ _hotspots (4), _accept (TRUE), _dirty_lines(pagesize)
error_box("Errore di scrittura file temporaneo: scrittura interrotta"); error_box("Errore di scrittura file temporaneo: scrittura interrotta");
freeze(); freeze();
} }
if (fgets (mytmpstr, sizeof (mytmpstr), _instr) == NULL) if (fgets (TEXT_TMP, sizeof (TEXT_TMP), _instr) == NULL)
break; break;
if (mytmpstr[strlen(mytmpstr)-1] == '\n') if (TEXT_TMP[strlen(TEXT_TMP)-1] == '\n')
mytmpstr[strlen(mytmpstr)-1] = '\0'; TEXT_TMP[strlen(TEXT_TMP)-1] = '\0';
if ((_lines) < (_page_start + _page_size)) if ((_lines) < (_page_start + _page_size))
{ {
TString *ll = new TString (mytmpstr); TString *ll = new TString (TEXT_TMP);
_page.add(ll); _page.add(ll);
_page_end++; _page_end++;

View File

@ -16,7 +16,8 @@
enum direction {up, down, updown}; enum direction {up, down, updown};
enum style {normal = XVT_FS_NONE, bold = XVT_FS_BOLD, italic = XVT_FS_ITALIC, underlined = XVT_FS_UNDERLINE }; enum style {normal = XVT_FS_NONE, bold = XVT_FS_BOLD, italic = XVT_FS_ITALIC,
underlined = XVT_FS_UNDERLINE, tabbed = XVT_FS_SCALE };
class TTextfile: public TObject class TTextfile: public TObject
{ {
@ -34,9 +35,12 @@ class TTextfile: public TObject
FILE* _index; FILE* _index;
FILE* _instr; FILE* _instr;
direction _direction; direction _direction;
TToken_string _line;
long _styles[256]; int _item; // Piece corrente
int _item; TToken_string _line; // Testo riga corrente
long _styles[256]; // Stile e colore carattere
bool _tabbed_piece;
TArray _hotspots; TArray _hotspots;
TArray _spots; TArray _spots;
bool _dirty; bool _dirty;
@ -88,7 +92,6 @@ public:
int get_style(int pos = -1); int get_style(int pos = -1);
char get_background(int pos = -1); char get_background(int pos = -1);
char get_foreground(int pos = -1); char get_foreground(int pos = -1);
long get_attribute(int pos = -1); long get_attribute(int pos = -1);
// ritorna la parola alla posizione indicata // ritorna la parola alla posizione indicata