diff --git a/ChangeLog b/ChangeLog index 3c7cc9c505..5d8546c13d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,53 @@ +2000-07-04 edscott + + * src/lyxrc.C, src/lyxrc.h, src/BufferView_pimpl.C, + lib/lyxrc.example: added option \wheel_jump + +2000-07-04 R. Lahaye + + * src/lyx_gui.C src/lyx_main.C: add support for -geometry, and + remove support for -width,-height,-xpos and -ypos. + +2000-07-01 Dekel Tsur + + * src/encoding.[Ch]: New files. + + * src/painter.C (text(int,int,XChar2b const *,...)): New method. + (text): Call to the underline() method only when needed. + + * src/font.C (XTextWidth16,width(XChar2b const *,...)): New methods. + + * src/buffer.C (makeLaTeXFile): Compute automatically the input + encoding(s) for the document. + + * src/bufferparams.C (BufferParams): Changed default value of + inputenc to "auto". + + * src/language.C (newLang): Removed. + (items[]): Added encoding information for all defined languages. + + * src/lyx_gui.C (create_forms): Added "auto" option to the input + encoding choice button. + + * src/lyxrc.h (font_norm_type): New member variable. + (set_font_norm_type): New method. + + * src/paragraph.C (TeXOnePar): Put "\inputencoding{}" between + paragraphs with different encodings. + + * src/text.C (is_arabic, is_nikud, TransformChar): Moved to encoding.C + (TransformChar): Changed to work correctly with Arabic points. + (draw): Added support for drawing Arabic points. + (draw): Removed code for drawing underbars (this is done by + the Painter!) + + * src/support/textutils.h (IsPrintableNonspace): New function. + + * src/BufferView_pimpl.h: Added "using SigC::Object". + * src/LyXView.h: ditto. + + * src/insets/insetinclude.h (include_label): Changed to mutable. + 2000-07-04 Lars Gullik Bjønnes * src/mathed/math_iter.h: remove empty destructor diff --git a/lib/lyxrc.example b/lib/lyxrc.example index 6066417547..1a27d199ec 100644 --- a/lib/lyxrc.example +++ b/lib/lyxrc.example @@ -207,6 +207,11 @@ # is 150%. #\screen_zoom 100 +# The wheel movement factor (for mice with wheels or five button mice) +# Default is 100, about a page down. A value of 10 give me about a line and +# a half +#\wheel_jump 10 + # LyX normally doesn't update the cursor position if you move the scrollbar. # If you scroll the cursor off the screen and then start typing LyX will # move you back to where the cursor was. If you'd prefer to always have the diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index df4a1244ad..4204726eff 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -535,10 +535,10 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos, if (button == 4 || button == 5) { switch (button) { case 4: - scrollUp(100); // This number is only temporary + scrollUp(lyxrc.wheel_jump); // default 100, set in lyxrc break; case 5: - scrollDown(100); + scrollDown(lyxrc.wheel_jump); break; } } diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 6ee7a9c4bf..4358e20197 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -16,7 +16,11 @@ class LyXView; class WorkArea; class LyXScreen; -struct BufferView::Pimpl : public SigC::Object { +#ifdef SIGC_CXX_NAMESPACES +using SigC::Object; +#endif + +struct BufferView::Pimpl : public Object { Pimpl(BufferView * i, LyXView * o, int xpos, int ypos, int width, int height); /// diff --git a/src/LyXView.h b/src/LyXView.h index 5fab87d125..23e2a30e66 100644 --- a/src/LyXView.h +++ b/src/LyXView.h @@ -29,13 +29,17 @@ class Menus; class BufferView; class Dialogs; +#ifdef SIGC_CXX_NAMESPACES +using SigC::Object; +#endif + /** This class is the form containing the view of the buffer. The actual buffer view is supposed (at least IMHO) to be another class, that shows its output in one or more LyXView's. */ -class LyXView : public SigC::Object { +class LyXView : public Object { public: /// constructor LyXView(int w, int h); diff --git a/src/Makefile.am b/src/Makefile.am index b5d2b9afef..82debf7ca1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -104,7 +104,8 @@ lyx_SOURCES = \ credits_form.h \ debug.C \ debug.h \ - direction.h \ + encoding.C \ + encoding.h \ figure.h \ filedlg.C \ filedlg.h \ diff --git a/src/Painter.C b/src/Painter.C index 603ac4e6ed..cb0cd4e740 100644 --- a/src/Painter.C +++ b/src/Painter.C @@ -30,6 +30,8 @@ #include "WorkArea.h" #include "font.h" #include "ColorHandler.h" +#include "lyxrc.h" +#include "encoding.h" using std::endl; using std::max; @@ -270,6 +272,19 @@ PainterBase & Painter::text(int x, int y, char c, LyXFont const & f) PainterBase & Painter::text(int x, int y, char const * s, int ls, LyXFont const & f) { + if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) { + XChar2b * xs = new XChar2b[ls]; + Encoding const * enc = f.language()->encoding(); + for (int i = 0; i < ls; ++i) { + Uchar c = enc->ucs(s[i]); + xs[i].byte1 = c >> 8; + xs[i].byte2 = c & 0xff; + } + text(x , y, xs, ls, f); + delete[] xs; + return *this; + } + if (lyxerr.debugging()) { if (!Lgb_bug_find_hack) lyxerr << "text not called from " @@ -303,21 +318,58 @@ PainterBase & Painter::text(int x, int y, char const * s, int ls, } } } - underline(f, x, y, lyxfont::width(s, ls, f)); + if (f.underbar() == LyXFont::ON && f.latex() != LyXFont::ON) + underline(f, x, y, lyxfont::width(s, ls, f)); + return *this; +} + + +PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls, + LyXFont const & f) +{ + if (lyxerr.debugging()) { + if (!Lgb_bug_find_hack) + lyxerr << "text not called from " + "workarea::workhandler\n"; + lyxerr << "Painter drawable: " << owner.getPixmap() << endl; + } + GC gc = lyxColorHandler->getGCForeground(f.realColor()); + if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { + lyxfont::XSetFont(display, gc, f); + XDrawString16(display, owner.getPixmap(), gc, x, y, s, ls); + } else { + LyXFont smallfont(f); + smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE); + static XChar2b c = {0, 0}; + int tmpx = x; + for(int i = 0; i < ls; ++i) { + if (s[i].byte1 == 0 && islower(s[i].byte2)) { + c.byte2 = toupper(s[i].byte2); + lyxfont::XSetFont(display, gc, smallfont); + XDrawString16(display, owner.getPixmap(), + gc, tmpx, y, &c, 1); + tmpx += lyxfont::XTextWidth16(smallfont, &c, 1); + } else { + lyxfont::XSetFont(display, gc, f); + XDrawString16(display, owner.getPixmap(), + gc, tmpx, y, &s[i], 1); + tmpx += lyxfont::XTextWidth16(f, const_cast(&s[i]), 1); + } + } + } + if (f.underbar() == LyXFont::ON && f.latex() != LyXFont::ON) + underline(f, x, y, lyxfont::width(s, ls, f)); return *this; } void Painter::underline(LyXFont const & f, int x, int y, int width) { - // What about underbars? - if (f.underbar() == LyXFont::ON && f.latex() != LyXFont::ON) { - int below = max(lyxfont::maxDescent(f) / 2, 2); - int height = max((lyxfont::maxDescent(f) / 4) - 1, 1); - if (height < 2) - line(x, y + below, x + width, y + below, f.color()); - else - fillRectangle(x, y + below, width, below + height, - f.color()); - } + int below = max(lyxfont::maxDescent(f) / 2, 2); + int height = max((lyxfont::maxDescent(f) / 4) - 1, 1); + if (height < 2) + line(x, y + below, x + width, y + below, f.color()); + else + fillRectangle(x, y + below, width, below + height, + f.color()); } diff --git a/src/Painter.h b/src/Painter.h index 8798428e75..7bba9cdde2 100644 --- a/src/Painter.h +++ b/src/Painter.h @@ -96,7 +96,10 @@ public: /// Draw a char at position x, y (y is the baseline) PainterBase & text(int x, int y, char c, LyXFont const & f); - + + /// Draw a wide string at position x, y + PainterBase & text(int x, int y, XChar2b const * str, int l, + LyXFont const & f); private: /// Check the font, and if set, draw an underline void underline(LyXFont const & f, int x, int y, int width); diff --git a/src/buffer.C b/src/buffer.C index 55785a6b3c..3ff1ddadc6 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -88,6 +88,7 @@ #include "language.h" #include "lyx_gui_misc.h" // WarnReadonly() #include "frontends/Dialogs.h" +#include "encoding.h" using std::ostream; using std::ofstream; @@ -99,6 +100,7 @@ using std::endl; using std::pair; using std::vector; using std::max; +using std::set; // all these externs should eventually be removed. extern BufferList bufferlist; @@ -1678,7 +1680,7 @@ void Buffer::makeLaTeXFile(string const & fname, // language should be a parameter to \documentclass bool use_babel = false; - if (params.language_info->RightToLeft()) // This seems necessary + if (params.language_info->lang() == "hebrew") // This seems necessary features.UsedLanguages.insert(default_language); if (params.language != "default" || !features.UsedLanguages.empty() ) { @@ -1717,12 +1719,32 @@ void Buffer::makeLaTeXFile(string const & fname, << "]{fontenc}\n"; texrow.newline(); } - if (params.inputenc != "default") { + + if (params.inputenc == "auto") { + string doc_encoding = + params.language_info->encoding()->LatexName(); + + // Create a list with all the input encodings used + // in the document + set encodings; + for (LaTeXFeatures::LanguageList::const_iterator it = + features.UsedLanguages.begin(); + it != features.UsedLanguages.end(); ++it) + if ((*it)->encoding()->LatexName() != doc_encoding) + encodings.insert((*it)->encoding()->LatexName()); + + ofs << "\\usepackage["; + for (set::const_iterator it = encodings.begin(); + it != encodings.end(); ++it) + ofs << *it << ","; + ofs << doc_encoding << "]{inputenc}\n"; + texrow.newline(); + } else if (params.inputenc != "default") { ofs << "\\usepackage[" << params.inputenc << "]{inputenc}\n"; texrow.newline(); } - + // At the very beginning the text parameters. if (params.paperpackage != BufferParams::PACKAGE_NONE) { switch (params.paperpackage) { diff --git a/src/bufferparams.C b/src/bufferparams.C index f45a5b2ca1..afa4c5b6bb 100644 --- a/src/bufferparams.C +++ b/src/bufferparams.C @@ -53,7 +53,7 @@ BufferParams::BufferParams() language = "default"; language_info = default_language; fonts = "default"; - inputenc = "latin1"; + inputenc = "auto"; graphicsDriver = "default"; sides = LyXTextClass::OneSide; columns = 1; diff --git a/src/direction.h b/src/direction.h deleted file mode 100644 index 4dcbef266b..0000000000 --- a/src/direction.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef DIRECTION_H -#define DIRECTION_H - -/// -enum LyXDirection { - /// - LYX_DIR_LEFT_TO_RIGHT = 1, - /// - LYX_DIR_RIGHT_TO_LEFT = -1 -}; - -#endif diff --git a/src/encoding.C b/src/encoding.C new file mode 100644 index 0000000000..c2a8bc53a9 --- /dev/null +++ b/src/encoding.C @@ -0,0 +1,336 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 Matthias Ettrich + * Copyright 1995-2000 The LyX Team. + * + * ====================================================== */ + +#include + +#include "encoding.h" + +Uchar tab_iso8859_1[256] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff +}; + +Uchar tab_iso8859_2[256] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, + 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b, + 0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7, + 0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c, + 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, + 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, + 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, + 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, + 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, + 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, + 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, + 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9 +}; + +Uchar tab_iso8859_4[256] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0x00a0, 0x0104, 0x0138, 0x0156, 0x00a4, 0x0128, 0x013b, 0x00a7, + 0x00a8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00ad, 0x017d, 0x00af, + 0x00b0, 0x0105, 0x02db, 0x0157, 0x00b4, 0x0129, 0x013c, 0x02c7, + 0x00b8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014a, 0x017e, 0x014b, + 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, + 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x012a, + 0x0110, 0x0145, 0x014c, 0x0136, 0x00d4, 0x00d5, 0x00d6, 0x00d7, + 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x0168, 0x016a, 0x00df, + 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, + 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x012b, + 0x0111, 0x0146, 0x014d, 0x0137, 0x00f4, 0x00f5, 0x00f6, 0x00f7, + 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9 +}; + +Uchar tab_iso8859_6_16[256] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667, + 0x0668, 0x0669, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x061f, + 0x0040, 0xfe80, 0xfe81, 0xfe83, 0xfe85, 0xfe87, 0xfe89, 0xfe8d, + 0xfe8f, 0xfe93, 0xfe95, 0xfe99, 0xfe9d, 0xfea1, 0xfea5, 0xfea9, + 0xfeab, 0xfead, 0xfeaf, 0xfeb1, 0xfeb5, 0xfeb9, 0xfebd, 0xfec1, + 0xfec5, 0xfec9, 0xfecd, 0x005d, 0x005c, 0x005b, 0x005e, 0x005f, + 0x0640, 0xfed1, 0xfed5, 0xfed9, 0xfedd, 0xfee1, 0xfee5, 0xfee9, + 0xfeed, 0xfeef, 0xfef1, 0x065b, 0x065c, 0x064d, 0x064e, 0x064f, + 0x0650, 0x0651, 0x0652, 0x0073, 0x0074, 0x0075, 0xfef5, 0xfef7, + 0xfef9, 0xfefb, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0xfe71, 0x0091, 0x0092, 0xfe77, 0xfe79, 0xfe7b, 0xfe7f, 0xfe7d, + 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, + 0xfe8c, 0xfe82, 0xfe84, 0xfe86, 0xfe88, 0xfe8e, 0xfeaa, 0xfeac, + 0xfeae, 0xfeb0, 0xfeee, 0xfef0, 0xfe91, 0xfe92, 0xfe90, 0xfe97, + 0xfe98, 0xfe94, 0xfe97, 0xfe98, 0xfe96, 0xfe9b, 0xfe9c, 0xfe9a, + 0xfe9f, 0xfea0, 0xfe9e, 0xfea3, 0xfea4, 0xfea2, 0xfea7, 0xfea8, + 0xfea6, 0xfeb3, 0xfeb4, 0xfeb2, 0xfeb7, 0xfeb8, 0xfeb6, 0xfebb, + 0xfebc, 0xfeba, 0xfebf, 0xfec0, 0xfebe, 0xfec3, 0xfec4, 0xfec2, + 0xfec7, 0xfec8, 0xfec6, 0xfecb, 0xfecc, 0xfeca, 0xfecf, 0xfed0, + 0xfece, 0xfed3, 0xfed4, 0xfed2, 0xfed7, 0xfed8, 0xfed6, 0xfedb, + 0xfedc, 0xfeda, 0xfedf, 0xfee0, 0xfede, 0xfee3, 0xfee4, 0xfee2, + 0xfee7, 0xfee8, 0xfee6, 0xfeeb, 0xfeec, 0xfeea, 0xfef3, 0xfef4, + 0xfef2, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, + 0xfe8b, 0xfe8a, 0xfef6, 0xfefa, 0xfef8, 0xfefc, 0x00fe, 0x00ff +}; + +Uchar tab_iso8859_7[256] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0x00a0, 0x0371, 0x0372, 0x00a3, 0xffff, 0xffff, 0x00a6, 0x00a7, + 0x00a8, 0x00a9, 0xffff, 0x00ab, 0x00ac, 0x00ad, 0xffff, 0x2015, + 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x03f3, 0x03f4, 0x0386, 0x00b7, + 0x0388, 0x0389, 0x038a, 0x00bb, 0x038c, 0x00bd, 0x038e, 0x038f, + 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, + 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, + 0x03a0, 0x03a1, 0xffff, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, + 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af, + 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, + 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, + 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, + 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0xffff +}; + +Uchar tab_cp1255[256] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0x00a0, 0xffff, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, + 0x00a8, 0x00a9, 0x00d7, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x203e, + 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, + 0x00b8, 0x00b9, 0x00f7, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, + 0x05b0, 0x05b1, 0x05b2, 0x05b3, 0x05b4, 0x05b5, 0x05b6, 0x05b7, + 0x05b8, 0x05b9, 0xffff, 0x05bb, 0x05bc, 0x05bd, 0x05be, 0x05bf, + 0x05c0, 0x05c1, 0x05c2, 0x05c3, 0x05f0, 0x05f1, 0x05f2, 0x05f3, + 0x05f4, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7, + 0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, 0x05de, 0x05df, + 0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7, + 0x05e8, 0x05e9, 0x05ea, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff +}; + +Uchar tab_koi8[256] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x2500, 0x2502, 0x250c, 0x2510, 0x2514, 0x2518, 0x251c, 0x2524, + 0x252c, 0x2534, 0x253c, 0x2580, 0x2584, 0x2588, 0x258c, 0x2590, + 0x2591, 0x2592, 0x2593, 0x2320, 0x25a0, 0x2219, 0x221a, 0x2248, + 0x2264, 0x2265, 0x00a0, 0x2321, 0x00b0, 0x00b2, 0x00b7, 0x00f7, + 0x2550, 0x2551, 0x2552, 0x0451, 0x2553, 0x2554, 0x2555, 0x2556, + 0x2557, 0x2558, 0x2559, 0x255a, 0x255b, 0x255c, 0x255d, 0x255e, + 0x255f, 0x2560, 0x2561, 0x0401, 0x2562, 0x2563, 0x2564, 0x2565, + 0x2566, 0x2567, 0x2568, 0x2569, 0x256a, 0x256b, 0x256c, 0x00a9, + 0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, + 0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, + 0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, + 0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a, + 0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, + 0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, + 0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, + 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a +}; + +unsigned char arabic_table2[63][4] = { + {0x41, 0x41, 0x41, 0x41}, // 0xc1 = hamza + {0x42, 0xa1, 0x42, 0x42}, // 0xc2 = ligature madda on alef + {0x43, 0xa2, 0x43, 0x43}, // 0xc3 = ligature hamza on alef + {0x44, 0xa3, 0x44, 0x44}, // 0xc4 = ligature hamza on waw + {0x45, 0xa4, 0x45, 0x45}, // 0xc5 = ligature hamza under alef + {0xf9, 0xf9, 0xf8, 0xa0}, // 0xc6 = ligature hamza on ya + {0x47, 0xa5, 0xa5, 0xa5}, // 0xc7 = alef + {0x48, 0xae, 0xac, 0xad}, // 0xc8 = baa + {0x49, 0xb1, 0xaf, 0xb0}, // 0xc9 = taa marbuta + {0x4a, 0xb4, 0xb2, 0xb3}, // 0xca = taa + {0x4b, 0xb7, 0xb5, 0xb6}, // 0xcb = thaa + {0x4c, 0xba, 0xb8, 0xb9}, // 0xcc = jeem + {0x4d, 0xbd, 0xbb, 0xbc}, // 0xcd = haa + {0x4e, 0xc0, 0xbe, 0xbf}, // 0xce = khaa + {0x4f, 0xa6, 0xa6, 0xa6}, // 0xcf = dal + + {0x50, 0xa7, 0xa7, 0xa7}, // 0xd0 = thal + {0x51, 0xa8, 0xa8, 0xa8}, // 0xd1 = ra + {0x52, 0xa9, 0xa9, 0xa9}, // 0xd2 = zain + {0x53, 0xc3, 0xc1, 0xc2}, // 0xd3 = seen + {0x54, 0xc6, 0xc4, 0xc5}, // 0xd4 = sheen + {0x55, 0xc9, 0xc7, 0xc8}, // 0xd5 = sad + {0x56, 0xcc, 0xca, 0xcb}, // 0xd6 = dad + {0x57, 0xcf, 0xcd, 0xce}, // 0xd7 = tah + {0x58, 0xd2, 0xd0, 0xd1}, // 0xd8 = zah + {0x59, 0xd5, 0xd3, 0xd4}, // 0xd9 = ain + {0x5a, 0xd8, 0xd6, 0xd7}, // 0xda = ghain + {0,0,0,0}, // 0xdb + {0,0,0,0}, // 0xdc + {0,0,0,0}, // 0xdd + {0,0,0,0}, // 0xde + {0,0,0,0}, // 0xdf + + {0,0,0,0}, // 0xe0 + {0x61, 0xdb, 0xd9, 0xda}, // 0xe1 = fa + {0x62, 0xde, 0xdc, 0xdd}, // 0xe2 = qaf + {0x63, 0xe1, 0xdf, 0xe0}, // 0xe3 = kaf + {0x64, 0xe4, 0xe2, 0xe3}, // 0xe4 = lam + {0x65, 0xe7, 0xe5, 0xe6}, // 0xe5 = meem + {0x66, 0xea, 0xe8, 0xe9}, // 0xe6 = noon + {0x67, 0xed, 0xeb, 0xec}, // 0xe7 = ha + {0x68, 0xaa, 0xaa, 0xaa}, // 0xe8 = waw + {0x69, 0xab, 0xab, 0xab}, // 0xe9 = alef maksura + {0x6a, 0xf0, 0xee, 0xef}, // 0xea = ya + {0x6b, 0x6b, 0x6b, 0x6b}, // 0xeb = fathatan + {0x6c, 0x6c, 0x6c, 0x6c}, // 0xec = dammatan + {0x6d, 0x6d, 0x6d, 0x6d}, // 0xed = kasratan + {0x6e, 0x6e, 0x6e, 0x6e}, // 0xee = fatha + {0x6f, 0x6f, 0x6f, 0x6f}, // 0xef = damma + + {0x70, 0x70, 0x70, 0x70}, // 0xf0 = kasra + {0x71, 0x71, 0x71, 0x71}, // 0xf1 = shadda + {0x72, 0x72, 0x72, 0x72}, // 0xf2 = sukun + {0,0,0,0}, // 0xf3 + {0,0,0,0}, // 0xf4 + {0,0,0,0}, // 0xf5 + {0,0,0,0}, // 0xf6 + {0,0,0,0}, // 0xf7 + {0,0,0,0}, // 0xf8 + {0,0,0,0}, // 0xf9 + {0,0,0,0}, // 0xfa + {0,0,0,0}, // 0xfb + {0,0,0,0}, // 0xfc + {0,0,0,0}, // 0xfd + {0,0,0,0}, // 0xfe + {0,0,0,0}, // 0xff +}; + +unsigned char arabic_table[63][2] = { + {0xc1, 0xc1}, // 0xc1 = hamza + {0xc2, 0xc2}, // 0xc2 = ligature madda on alef + {0xc3, 0xc3}, // 0xc3 = ligature hamza on alef + {0xc4, 0xc4}, // 0xc4 = ligature hamza on waw + {0xc5, 0xc5}, // 0xc5 = ligature hamza under alef + {0xc6, 0xc0}, // 0xc6 = ligature hamza on ya + {0xc7, 0xc7}, // 0xc7 = alef + {0xc8, 0xeb}, // 0xc8 = baa + {0xc9, 0xc9}, // 0xc9 = taa marbuta + {0xca, 0xec}, // 0xca = taa + {0xcb, 0xed}, // 0xcb = thaa + {0xcc, 0xee}, // 0xcc = jeem + {0xcd, 0xef}, // 0xcd = haa + {0xce, 0xf0}, // 0xce = khaa + {0xcf, 0xcf}, // 0xcf = dal + + {0xd0, 0xd0}, // 0xd0 = thal + {0xd1, 0xd1}, // 0xd1 = ra + {0xd2, 0xd2}, // 0xd2 = zain + {0xd3, 0xf1}, // 0xd3 = seen + {0xd4, 0xf2}, // 0xd4 = sheen + {0xd5, 0xf3}, // 0xd5 = sad + {0xd6, 0xf4}, // 0xd6 = dad + {0xd7, 0xd7}, // 0xd7 = tah + {0xd8, 0xd8}, // 0xd8 = zah + {0xd9, 0xf5}, // 0xd9 = ain + {0xda, 0xf6}, // 0xda = ghain + {0,0}, // 0xdb + {0,0}, // 0xdc + {0,0}, // 0xdd + {0,0}, // 0xde + {0,0}, // 0xdf + + {0,0}, // 0xe0 + {0xe1, 0xf7}, // 0xe1 = fa + {0xe2, 0xf8}, // 0xe2 = qaf + {0xe3, 0xf9}, // 0xe3 = kaf + {0xe4, 0xfa}, // 0xe4 = lam + {0xe5, 0xfb}, // 0xe5 = meem + {0xe6, 0xfc}, // 0xe6 = noon + {0xe7, 0xfd}, // 0xe7 = ha + {0xe8, 0xe8}, // 0xe8 = waw + {0xe9, 0xe9}, // 0xe9 = alef maksura + {0xea, 0xfe}, // 0xea = ya + {0xeb, 0xa8}, // 0xeb = fathatan + {0xa9, 0xa9}, // 0xec = dammatan + {0xaa, 0xaa}, // 0xed = kasratan + {0xab, 0xab}, // 0xee = fatha + {0xac, 0xac}, // 0xef = damma + + {0xad, 0xad}, // 0xf0 = kasra + {0xae, 0xae}, // 0xf1 = shadda + {0xaf, 0xaf}, // 0xf2 = sukun + {0,0}, // 0xf3 + {0,0}, // 0xf4 + {0,0}, // 0xf5 + {0,0}, // 0xf6 + {0,0}, // 0xf7 + {0,0}, // 0xf8 + {0,0}, // 0xf9 + {0,0}, // 0xfa + {0,0}, // 0xfb + {0,0}, // 0xfc + {0,0}, // 0xfd + {0,0}, // 0xfe + {0,0} // 0xff +}; + +Encoding iso8859_1("latin1",tab_iso8859_1); +Encoding iso8859_2("latin2",tab_iso8859_2); +Encoding iso8859_4("latin4",tab_iso8859_4); +Encoding iso8859_6("latin6",tab_iso8859_6_16); +Encoding iso8859_7("latin7",tab_iso8859_7); +Encoding cp1255("cp1255",tab_cp1255); +Encoding koi8("koi8-r",tab_koi8); diff --git a/src/encoding.h b/src/encoding.h new file mode 100644 index 0000000000..4f21877e5c --- /dev/null +++ b/src/encoding.h @@ -0,0 +1,109 @@ +// -*- C++ -*- +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 Matthias Ettrich + * Copyright 1995-2000 The LyX Team. + * + * ====================================================== */ + +#ifndef ENCODING_H +#define ENCODING_H + +#include "LString.h" +#include "lyxrc.h" + +typedef unsigned short int Uchar; + +class Encoding { +public: + /// + enum Letter_Form { + FORM_ISOLATED, + FORM_FINAL, + FORM_INITIAL, + FORM_MEDIAL + }; + /// + Encoding(string const & l, Uchar const * e) + : LatexName_(l) , encoding_table(e) {} + /// + string const & LatexName() const { + return LatexName_; + } + /// + Uchar ucs(unsigned char c) const { + return encoding_table[c]; + } + /// + static + bool IsComposeChar_hebrew(unsigned char c); + /// + static + bool IsComposeChar_arabic(unsigned char c); + /// + static + bool is_arabic(unsigned char c); + /// + static + unsigned char TransformChar(unsigned char c, Letter_Form form); +private: + /// + string LatexName_; + /// + Uchar const * encoding_table; +}; + + +extern Encoding iso8859_1; +extern Encoding iso8859_2; +extern Encoding iso8859_4; +extern Encoding iso8859_6; +extern Encoding iso8859_7; +extern Encoding cp1255; +extern Encoding koi8; + + +inline +bool Encoding::IsComposeChar_hebrew(unsigned char c) +{ + return c <= 0xd2 && c >= 0xc0 && + c != 0xce && c != 0xd0; +} + + +inline +bool Encoding::IsComposeChar_arabic(unsigned char c) +{ + return c >= 0xeb && c <= 0xf2; +} + + +extern unsigned char arabic_table[][2]; +extern unsigned char arabic_table2[][4]; +unsigned char const arabic_start = 0xc1; + + +inline +bool Encoding::is_arabic(unsigned char c) +{ + return c >= arabic_start && arabic_table[c-arabic_start][0]; +} + + +inline +unsigned char Encoding::TransformChar(unsigned char c, Encoding::Letter_Form form) +{ + if (!is_arabic(c)) + return c; + + if (lyxrc.font_norm == "iso10646-1") + return arabic_table2[c-arabic_start][form]; + else + return arabic_table[c-arabic_start][form >> 1]; +} + + +#endif diff --git a/src/font.C b/src/font.C index 1590c72b55..c17c8da8f8 100644 --- a/src/font.C +++ b/src/font.C @@ -5,8 +5,7 @@ #include "font.h" #include "FontLoader.h" #include "lyxrc.h" - -extern LyXRC lyxrc; +#include "encoding.h" // namespace { static inline @@ -88,29 +87,24 @@ int lyxfont::rbearing(char c, LyXFont const & f) } -int lyxfont::width(char c, LyXFont const & f) -{ - if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { - return lyxrc.use_gui ? ::XTextWidth(getXFontstruct(f), &c, 1) - : 1; - } else { - LyXFont smallfont(f); - smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE); - if (islower(static_cast(c))) { - c = toupper(c); - return ::XTextWidth(getXFontstruct(smallfont), &c, 1); - } else { - return ::XTextWidth(getXFontstruct(f), &c, 1); - } - } -} - - int lyxfont::width(char const * s, int n, LyXFont const & f) { if (!lyxrc.use_gui) return n; - + + if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) { + XChar2b * xs = new XChar2b[n]; + Encoding const * enc = f.language()->encoding(); + for (int i = 0; i < n; ++i) { + Uchar c = enc->ucs(s[i]); + xs[i].byte1 = c >> 8; + xs[i].byte2 = c & 0xff; + } + int result = width(xs, n, f); + delete[] xs; + return result; + } + if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { return ::XTextWidth(getXFontstruct(f), s, n); } else { @@ -144,12 +138,43 @@ int lyxfont::signedWidth(string const & s, LyXFont const & f) } +int lyxfont::width(XChar2b const * s, int n, LyXFont const & f) +{ + if (!lyxrc.use_gui) + return n; + + if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { + return ::XTextWidth16(getXFontstruct(f), s, n); + } else { + // emulate smallcaps since X doesn't support this + unsigned int result = 0; + static XChar2b c = {0, 0}; + LyXFont smallfont(f); + smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE); + for (int i = 0; i < n; ++i) { + if (s[i].byte1 == 0 && islower(s[i].byte2)) { + c.byte2 = toupper(s[i].byte2); + result += ::XTextWidth16(getXFontstruct(smallfont), &c, 1); + } else { + result += ::XTextWidth16(getXFontstruct(f), &s[i], 1); + } + } + return result; + } +} + int lyxfont::XTextWidth(LyXFont const & f, char * str, int count) { return ::XTextWidth(getXFontstruct(f), str, count); } +int lyxfont::XTextWidth16(LyXFont const & f, XChar2b * str, int count) +{ + return ::XTextWidth16(getXFontstruct(f), str, count); +} + + void lyxfont::XSetFont(Display * display, GC gc, LyXFont const & f) { ::XSetFont(display, gc, getFontID(f)); diff --git a/src/font.h b/src/font.h index 0a7fb27164..28c3a017d9 100644 --- a/src/font.h +++ b/src/font.h @@ -32,7 +32,9 @@ struct lyxfont { int rbearing(char c, LyXFont const & f); static - int width(char c, LyXFont const & f); + int width(char c, LyXFont const & f) { + return width(&c, 1, f); + } static int width(char const * s, int n, LyXFont const & f); @@ -54,6 +56,12 @@ struct lyxfont { static int XTextWidth(LyXFont const & f, char * str, int count); + static + int width(XChar2b const * s, int n, LyXFont const & f); + + static + int XTextWidth16(LyXFont const & f, XChar2b * str, int count); + static void XSetFont(Display * display, GC gc, LyXFont const & f); }; diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 8bb15af631..5dc86d56fc 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -125,7 +125,7 @@ private: /// string filename; /// - string include_label; + mutable string include_label; }; diff --git a/src/language.C b/src/language.C index cee95f73db..f439153ae0 100644 --- a/src/language.C +++ b/src/language.C @@ -3,10 +3,11 @@ #include "language.h" #include "gettext.h" +#include "encoding.h" Languages languages; Language const * default_language; -Language ignore_lang("ignore", "Ignore", false); +Language ignore_lang("ignore", "Ignore", false, 0); Language const * ignore_language = &ignore_lang; /// @@ -18,14 +19,6 @@ public: init = true; } private: - /// - void newLang(char const * l, char const * d, bool rtl) { - Language lang(l, d, rtl); - //lang.lang = l; - //lang.display = d; - //lang.RightToLeft = rtl; - languages[l] = lang; - } /// void initL(); /// @@ -37,6 +30,7 @@ struct lang_item { char const * lang; char const * display; bool rtl; + Encoding const * encoding; }; @@ -44,59 +38,61 @@ void LangInit::initL() { // Use this style of initialization to lower compilation times. // Same method is used in LyXAction.C (Lgb) - + lang_item items[] = { - { "afrikaans", N_("Afrikaans"), false }, - { "american", N_("American"), false }, - { "arabic", N_("Arabic"), true }, - { "austrian", N_("Austrian"), false }, - { "bahasa", N_("Bahasa"), false }, - { "brazil", N_("Brazil"), false }, - { "breton", N_("Breton"), false }, - { "catalan", N_("Catalan"), false }, - { "croatian", N_("Croatian"), false }, - { "czech", N_("Czech"), false }, - { "danish", N_("Danish"), false }, - { "dutch", N_("Dutch"), false }, - { "english", N_("English"), false }, - { "esperanto", N_("Esperanto"), false }, - { "estonian", N_("Estonian"), false }, - { "finnish", N_("Finnish"), false }, - { "francais", N_("Francais"), false }, - { "french", N_("French"), false }, - { "frenchb", N_("Frenchb"), false }, - { "galician", N_("Galician"), false }, - { "german", N_("German"), false }, - { "greek", N_("Greek"), false }, - { "hebrew", N_("Hebrew"), true }, + { "afrikaans", N_("Afrikaans"), false, &iso8859_1 }, + { "american", N_("American"), false, &iso8859_1 }, + { "arabic", N_("Arabic"), true, &iso8859_6 }, + { "austrian", N_("Austrian"), false, &iso8859_1 }, + { "bahasa", N_("Bahasa"), false, &iso8859_1 }, + { "brazil", N_("Brazil"), false, &iso8859_1 }, + { "breton", N_("Breton"), false, &iso8859_1 }, + { "catalan", N_("Catalan"), false, &iso8859_1 }, + { "croatian", N_("Croatian"), false, &iso8859_2 }, + { "czech", N_("Czech"), false, &iso8859_2 }, + { "danish", N_("Danish"), false, &iso8859_1 }, + { "dutch", N_("Dutch"), false, &iso8859_1 }, + { "english", N_("English"), false, &iso8859_1 }, + { "esperanto", N_("Esperanto"), false, &iso8859_1 }, + { "estonian", N_("Estonian"), false, &iso8859_4 }, + { "finnish", N_("Finnish"), false, &iso8859_1 }, + { "francais", N_("Francais"), false, &iso8859_1 }, + { "french", N_("French"), false, &iso8859_1 }, + { "frenchb", N_("Frenchb"), false, &iso8859_1 }, + { "galician", N_("Galician"), false, &iso8859_1 }, + { "german", N_("German"), false, &iso8859_1 }, + { "greek", N_("Greek"), false, &iso8859_7 }, + { "hebrew", N_("Hebrew"), true, &cp1255 }, /* According to Zrubecz Laszlo , "magyar" is better. I kept it here in case we want to provide aliasing of languages. (JMarc) */ - //{ "hungarian", N_("Hungarian"), false }, - { "irish", N_("Irish"), false }, - { "italian", N_("Italian"), false }, - { "lsorbian", N_("Lsorbian"), false }, - { "magyar", N_("Magyar"), false }, - { "norsk", N_("Norsk"), false }, - { "polish", N_("Polish"), false }, - { "portuges", N_("Portuges"), false }, - { "romanian", N_("Romanian"), false }, - { "russian", N_("Russian"), false }, - { "scottish", N_("Scottish"), false }, - { "spanish", N_("Spanish"), false }, - { "slovak", N_("Slovak"), false }, - { "slovene", N_("Slovene"), false }, - { "swedish", N_("Swedish"), false }, - { "turkish", N_("Turkish"), false }, - { "usorbian", N_("Usorbian"), false }, - { "welsh", N_("Welsh"), false }, - { 0, 0, false } + //{ "hungarian", N_("Hungarian"), false, &iso8859_2 }, + { "irish", N_("Irish"), false, &iso8859_1 }, + { "italian", N_("Italian"), false, &iso8859_1 }, + { "lsorbian", N_("Lsorbian"), false, &iso8859_1 }, + { "magyar", N_("Magyar"), false, &iso8859_1 }, + { "norsk", N_("Norsk"), false, &iso8859_1 }, + { "polish", N_("Polish"), false, &iso8859_2 }, + { "portuges", N_("Portuges"), false, &iso8859_1 }, + { "romanian", N_("Romanian"), false, &iso8859_2 }, + { "russian", N_("Russian"), false, &koi8 }, + { "scottish", N_("Scottish"), false, &iso8859_1 }, + { "spanish", N_("Spanish"), false, &iso8859_1 }, + { "slovak", N_("Slovak"), false, &iso8859_2 }, + { "slovene", N_("Slovene"), false, &iso8859_2 }, + { "swedish", N_("Swedish"), false, &iso8859_1 }, + { "turkish", N_("Turkish"), false, &iso8859_1 }, + { "usorbian", N_("Usorbian"), false, &iso8859_1 }, + { "welsh", N_("Welsh"), false, &iso8859_1 }, + { 0, 0, false, 0 } }; int i = 0; while (items[i].lang) { - newLang(items[i].lang, items[i].display, items[i].rtl); + languages[items[i].lang] = + Language(items[i].lang, items[i].display, + items[i].rtl, items[i].encoding); ++i; } diff --git a/src/language.h b/src/language.h index d3b42fb1a7..3538c208d6 100644 --- a/src/language.h +++ b/src/language.h @@ -5,14 +5,16 @@ #include #include "LString.h" +class Encoding; + /// class Language { public: /// Language() : RightToLeft_(false) {} /// - Language(string const & l, string const & d, bool rtl) - : lang_(l), display_(d), RightToLeft_(rtl) {} + Language(string const & l, string const & d, bool rtl, Encoding const * e) + : lang_(l), display_(d), RightToLeft_(rtl) , encoding_(e) {} /// string const & lang() const { return lang_; @@ -25,6 +27,10 @@ public: bool RightToLeft() const { return RightToLeft_; } + /// + Encoding const * encoding() const { + return encoding_; + } private: /// string lang_; @@ -32,14 +38,17 @@ private: string display_; /// bool RightToLeft_; + /// + Encoding const * encoding_; }; #if 0 bool operator==(Language const & l1, Language const & l2) { return l1.lang == l2.lang - && l1.display == l2.display - && l1.RightToLeft == l2.RightToLeft; + && l1.display_ == l2.display_ + && l1.RightToLeft_ == l2.RightToLeft_ + && l1.encoding_ == l2.encoding_; } diff --git a/src/lyx_cb.C b/src/lyx_cb.C index b8cbbb89a2..cd43250aae 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -2785,6 +2785,7 @@ extern "C" void ScreenApplyCB(FL_OBJECT *, long) lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans); lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter); lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm); + lyxrc.set_font_norm_type(); lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size)); fontloader.update(); diff --git a/src/lyx_gui.C b/src/lyx_gui.C index e80bc7a0a1..e518b420ed 100644 --- a/src/lyx_gui.C +++ b/src/lyx_gui.C @@ -78,25 +78,20 @@ extern BufferList bufferlist; FL_CMD_OPT cmdopt[] = { - {"-width", "*.width", XrmoptionSepArg, "690"}, - {"-height", "*.height", XrmoptionSepArg, "510"}, - {"-xpos", "*.xpos", XrmoptionSepArg, "-1"}, - {"-ypos", "*.ypos", XrmoptionSepArg, "-1"} + {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"} }; -static int width; -static int height; -static int xpos; -static int ypos; +static int width = 690; +static int height = 510; +static int xpos = -1; +static int ypos = -1; +static char geometry[40]; bool cursor_follows_scrollbar; FL_resource res[] = { - {"width", "widthClass", FL_INT, &width, "690", 0}, - {"height", "heightClass", FL_INT, &height, "510", 0}, - {"xpos", "xposClass", FL_INT, &xpos, "-1", 0}, - {"ypos", "yposClass", FL_INT, &ypos, "-1", 0} + {"geometry", "geometryClass", FL_STRING, geometry, "690x510", 40} }; @@ -130,6 +125,8 @@ LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI) fl_initialize(argc, argv, "LyX", cmdopt, num_res); fl_get_app_resources(res, num_res); + XParseGeometry(geometry, &xpos, &ypos, (unsigned int *) &width, (unsigned int *) &height); + Display * display = fl_get_display(); if (!display) { lyxerr << "LyX: unable to access X display, exiting" << endl; @@ -416,7 +413,7 @@ void LyXGUI::create_forms() } fl_addto_choice(fd_form_document->choice_inputenc, - "default|latin1|latin2|latin5" + "default|auto|latin1|latin2|latin5" "|koi8-r|koi8-u|cp866|cp1251|iso88595"); for (n = 0; tex_graphics[n][0]; ++n) { diff --git a/src/lyx_main.C b/src/lyx_main.C index db2e00c1aa..5e5062a9e2 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -591,13 +591,10 @@ void commandLineHelp() lyxerr << _("Usage: lyx [ command line switches ] [ name.lyx ... ]\n" "Command line switches (case sensitive):\n" - "\t-help summarize LyX usage\n" - "\t-userdir dir try to set user directory to dir\n" - "\t-sysdir dir try to set system directory to dir\n" - "\t-width x set the width of the main window\n" - "\t-height y set the height of the main window\n" - "\t-xpos x set the x position of the main window\n" - "\t-ypos y set the y position of the main window\n" + "\t-help summarize LyX usage\n" + "\t-userdir dir try to set user directory to dir\n" + "\t-sysdir dir try to set system directory to dir\n" + "\t-geometry WxH+X+Y set the width of the main window\n" "\t-dbg feature[,feature]...\n" " select the features to debug.\n" " Type `lyx -dbg' to see the list of features\n" diff --git a/src/lyxrc.C b/src/lyxrc.C index 2b81b0d0c3..114dfcfc7c 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -154,6 +154,7 @@ enum LyXRCTags { RC_DOCBOOK_TO_DVI_COMMAND, RC_DOCBOOK_TO_HTML_COMMAND, RC_DOCBOOK_TO_PDF_COMMAND, + RC_WHEEL_JUMP, RC_LAST }; @@ -266,7 +267,8 @@ keyword_item lyxrcTags[] = { { "\\view_dvi_paper_option", RC_VIEWDVI_PAPEROPTION }, { "\\view_pdf_command", RC_VIEWPDF_COMMAND }, { "\\view_ps_command", RC_VIEWPS_COMMAND }, - { "\\view_pspic_command", RC_VIEWPSPIC_COMMAND } + { "\\view_pspic_command", RC_VIEWPSPIC_COMMAND }, + { "\\wheel_jump", RC_WHEEL_JUMP } }; /* Let the range depend of the size of lyxrcTags. Alejandro 240596 */ @@ -325,6 +327,7 @@ void LyXRC::setDefaults() { dpi = 75; // Because a screen typically is wider than a piece of paper: zoom = 150; + wheel_jump = 100; // Default LaTeX font size: font_sizes[LyXFont::SIZE_TINY] = 5.0; font_sizes[LyXFont::SIZE_SCRIPT] = 7.0; @@ -343,6 +346,7 @@ void LyXRC::setDefaults() { menu_font_name = "-*-helvetica-bold-r"; popup_font_name = "-*-helvetica-medium-r"; font_norm = "iso8859-1"; + font_norm_type = OTHER_ENCODING; font_norm_menu = ""; override_x_deadkeys = true; autosave = 300; @@ -732,6 +736,11 @@ int LyXRC::read(string const & filename) if (lexrc.next()) zoom = lexrc.GetInteger(); break; + + case RC_WHEEL_JUMP: + if (lexrc.next()) + wheel_jump = lexrc.GetInteger(); + break; case RC_SCREEN_FONT_SIZES: if (lexrc.next()) @@ -838,8 +847,10 @@ int LyXRC::read(string const & filename) break; case RC_SCREEN_FONT_ENCODING: - if (lexrc.next()) + if (lexrc.next()) { font_norm = lexrc.GetString(); + set_font_norm_type(); + } break; case RC_SCREEN_FONT_ENCODING_MENU: @@ -1222,6 +1233,8 @@ void LyXRC::output(ostream & os) const os << "\\screen_dpi " << dpi << "\n"; case RC_SCREEN_ZOOM: os << "\\screen_zoom " << zoom << "\n"; + case RC_WHEEL_JUMP: + os << "\\wheel_jump " << wheel_jump << "\n"; case RC_SCREEN_FONT_SIZES: os.setf(ios::fixed); os.precision(2); @@ -1421,6 +1434,15 @@ void LyXRC::output(ostream & os) const os.flush(); } +void LyXRC::set_font_norm_type() +{ + if (font_norm == "iso10646-1") + font_norm_type = ISO_10646_1; + else if (font_norm == "iso8859-6.8x") + font_norm_type = ISO_8859_6_8; + else + font_norm_type = OTHER_ENCODING; +} // The global instance LyXRC lyxrc; diff --git a/src/lyxrc.h b/src/lyxrc.h index 7eec3c242f..3cf27a9243 100644 --- a/src/lyxrc.h +++ b/src/lyxrc.h @@ -140,6 +140,8 @@ public: string backupdir_path; /// Zoom factor for screen fonts unsigned int zoom; + /// parameter for button_4 and button_5 (scrollwheel) + unsigned int wheel_jump; /// Screen font sizes in points for each font size float font_sizes[10]; /// Allow the use of scalable fonts? Default is yes. @@ -162,6 +164,14 @@ public: string popup_font_name; /// string font_norm; + enum FontEncoding { + ISO_10646_1, + ISO_8859_6_8, + OTHER_ENCODING + }; + FontEncoding font_norm_type; + /// + void set_font_norm_type(); /// string font_norm_menu; /// diff --git a/src/lyxtext.h b/src/lyxtext.h index 4883211447..71b365c5e1 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -44,13 +44,6 @@ public: NEED_VERY_LITTLE_REFRESH }; - enum Letter_Form { - FORM_ISOLATED, - FORM_INITIAL, - FORM_MEDIAL, - FORM_FINAL - }; - /// Constructor LyXText(BufferView *); LyXText(InsetText *); @@ -676,9 +669,6 @@ private: /// mutable bool bidi_same_direction; - /// - unsigned char TransformChar(unsigned char c, Letter_Form form) const; - /// unsigned char TransformChar(unsigned char c, LyXParagraph * par, LyXParagraph::size_type pos) const; diff --git a/src/paragraph.C b/src/paragraph.C index 449acc3adc..34f9ee9293 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -36,6 +36,7 @@ #include "texrow.h" #include "support/lyxmanip.h" #include "BufferView.h" +#include "encoding.h" using std::ostream; using std::endl; @@ -2092,13 +2093,22 @@ LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf, Language const * language = getParLanguage(bparams); Language const * doc_language = bparams.language_info; - if (language != doc_language && - (!previous || previous->getParLanguage(bparams) != language)) { + Language const * previous_language = previous + ? previous->getParLanguage(bparams) : doc_language; + if (language != doc_language && language != previous_language) { os << subst(lyxrc.language_command_begin, "$$lang", language->lang()) << endl; texrow.newline(); } + + if (bparams.inputenc == "auto" && + language->encoding() != previous_language->encoding()) { + os << "\\inputencoding{" + << language->encoding()->LatexName() + << "}" << endl; + texrow.newline(); + } switch (style.latextype) { case LATEX_COMMAND: @@ -3315,7 +3325,10 @@ void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf, case '°': case '±': case '²': case '³': case '×': case '÷': case '¹': case 'ª': case 'º': case '¬': case 'µ': - if (bparams.inputenc == "latin1") { + if (bparams.inputenc == "latin1" || + (bparams.inputenc == "auto" && + font.language()->encoding()->LatexName() + == "latin1")) { os << "\\ensuremath{" << c << '}'; diff --git a/src/spellchecker.C b/src/spellchecker.C index d44a128e90..d20989eb33 100644 --- a/src/spellchecker.C +++ b/src/spellchecker.C @@ -50,6 +50,7 @@ #include "lyx_gui_misc.h" #include "debug.h" #include "support/lstrings.h" +#include "encoding.h" using std::reverse; using std::endl; @@ -327,13 +328,17 @@ void create_ispell_pipe(BufferParams const & params, string const & lang) argv[argc++] = tmp; } if (lyxrc.isp_use_input_encoding && - params.inputenc != "default") { + params.inputenc != "default") { + string enc = (params.inputenc == "auto") + ? params.language_info->encoding()->LatexName() + : params.inputenc; + string::size_type n = enc.length(); tmp = new char[3]; string("-T").copy(tmp, 2); tmp[2] = '\0'; argv[argc++] = tmp; // Input encoding - tmp = new char[params.inputenc.length() + 1]; - params.inputenc.copy(tmp, params.inputenc.length()); - tmp[params.inputenc.length()] = '\0'; + tmp = new char[n + 1]; + enc.copy(tmp, n); + tmp[n] = '\0'; argv[argc++] = tmp; } diff --git a/src/support/textutils.h b/src/support/textutils.h index a25a87bf7e..0427659fcf 100644 --- a/src/support/textutils.h +++ b/src/support/textutils.h @@ -109,6 +109,13 @@ bool IsPrintable(unsigned char c) { } +/// +inline +bool IsPrintableNonspace(unsigned char c) { + return (c > ' '); +} + + /// Word is not IsSeparator or IsKomma or IsHfill or IsFloat or IsInset. inline bool IsWordChar(unsigned char c) { diff --git a/src/text.C b/src/text.C index 525bb54610..daa91a2aba 100644 --- a/src/text.C +++ b/src/text.C @@ -35,6 +35,7 @@ #include "Painter.h" #include "tracer.h" #include "font.h" +#include "encoding.h" using std::max; using std::min; @@ -44,75 +45,6 @@ using std::pair; static const int LYX_PAPER_MARGIN = 20; extern int bibitemMaxWidth(Painter &, LyXFont const &); -static int iso885968x[] = { - 0xbc, // 0xa8 = fathatan - 0xbd, // 0xa9 = dammatan - 0xbe, // 0xaa = kasratan - 0xdb, // 0xab = fatha - 0xdc, // 0xac = damma - 0xdd, // 0xad = kasra - 0xde, // 0xae = shadda - 0xdf, // 0xaf = sukun - - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xb0-0xbf - - 0, // 0xc0 - 0xc1, // 0xc1 = hamza - 0xc2, // 0xc2 = ligature madda - 0xc3, // 0xc3 = ligature hamza on alef - 0xc4, // 0xc4 = ligature hamza on waw - 0xc5, // 0xc5 = ligature hamza under alef - 0xc0, // 0xc6 = ligature hamza on ya - 0xc7, // 0xc7 = alef - 0xeb, // 0xc8 = baa - 0xc9, // 0xc9 = taa marbuta - 0xec, // 0xca = taa - 0xed, // 0xcb = thaa - 0xee, // 0xcc = jeem - 0xef, // 0xcd = haa - 0xf0, // 0xce = khaa - 0xcf, // 0xcf = dal - - 0xd0, // 0xd0 = thal - 0xd1, // 0xd1 = ra - 0xd2, // 0xd2 = zain - 0xf1, // 0xd3 = seen - 0xf2, // 0xd4 = sheen - 0xf3, // 0xd5 = sad - 0xf4, // 0xd6 = dad - 0xd7, // 0xd7 = tah - 0xd8, // 0xd8 = zah - 0xf5, // 0xd9 = ain - 0xf6, // 0xda = ghain - 0,0,0,0,0, // 0xdb- 0xdf - - 0, // 0xe0 - 0xf7, // 0xe1 = fa - 0xf8, // 0xe2 = qaf - 0xf9, // 0xe3 = kaf - 0xfa, // 0xe4 = lam - 0xfb, // 0xe5 = meem - 0xfc, // 0xe6 = noon - 0xfd, // 0xe7 = ha - 0xe8, // 0xe8 = waw - 0xe9, // 0xe9 = alef maksura - 0xfe // 0xea = ya -}; - - -inline -bool is_arabic(unsigned char c) -{ - return 0xa8 <= c && c <= 0xea && iso885968x[c-0xa8]; -} - - -inline -bool is_nikud(unsigned char c) -{ - return 192 <= c && c <= 210; -} - int LyXText::workWidth(BufferView * bview) const { @@ -122,36 +54,34 @@ int LyXText::workWidth(BufferView * bview) const return bview->workWidth(); } -unsigned char LyXText::TransformChar(unsigned char c, Letter_Form form) const -{ - if (is_arabic(c) && - (form == FORM_INITIAL || form == FORM_MEDIAL) ) - return iso885968x[c-0xa8]; - else - return c; -} - unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par, LyXParagraph::size_type pos) const { - if (!is_arabic(c)) - if (isdigit(c)) + if (!Encoding::is_arabic(c)) + if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && isdigit(c)) return c + (0xb0 - '0'); else return c; - bool not_first = (pos > 0 && is_arabic(par->GetChar(pos-1))); - if (pos < par->Last()-1 && is_arabic(par->GetChar(pos+1))) - if (not_first) - return TransformChar(c,FORM_MEDIAL); + unsigned char prev_char = pos > 0 ? par->GetChar(pos-1) : ' '; + unsigned char next_char = ' '; + for (LyXParagraph::size_type i = pos+1; i < par->Last(); ++i) + if (!Encoding::IsComposeChar_arabic(par->GetChar(i))) { + next_char = par->GetChar(i); + break; + } + + if (Encoding::is_arabic(next_char)) + if (Encoding::is_arabic(prev_char)) + return Encoding::TransformChar(c, Encoding::FORM_MEDIAL); else - return TransformChar(c,FORM_INITIAL); + return Encoding::TransformChar(c, Encoding::FORM_INITIAL); else - if (not_first) - return TransformChar(c,FORM_FINAL); + if (Encoding::is_arabic(prev_char)) + return Encoding::TransformChar(c, Encoding::FORM_FINAL); else - return TransformChar(c,FORM_ISOLATED); + return Encoding::TransformChar(c, Encoding::FORM_ISOLATED); } // This is the comments that some of the warnings below refers to. @@ -196,10 +126,14 @@ int LyXText::SingleWidth(BufferView * bview, LyXParagraph * par, if (IsPrintable(c)) { if (font.language()->RightToLeft()) { if (font.language()->lang() == "arabic" && - lyxrc.font_norm == "iso8859-6.8x") - c = TransformChar(c, par, pos); + (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 || + lyxrc.font_norm_type == LyXRC::ISO_10646_1)) + if (Encoding::IsComposeChar_arabic(c)) + return 0; + else + c = TransformChar(c, par, pos); else if (font.language()->lang() == "hebrew" && - is_nikud(c)) + Encoding::IsComposeChar_hebrew(c)) return 0; } return lyxfont::width(c, font); @@ -603,20 +537,19 @@ void LyXText::draw(BufferView * bview, Row const * row, LyXParagraph::size_type last = RowLastPrintable(row); if (font.language()->lang() == "hebrew") { - if (is_nikud(c)) { - LyXParagraph::size_type vpos2 = vpos; + if (Encoding::IsComposeChar_hebrew(c)) { int width = lyxfont::width(c, font2); int dx = 0; - while (vpos2 <= last && - (pos = vis2log(vpos2)) >= 0 - && static_cast(c = row->par()->GetChar(pos)) > ' ' - && is_nikud(c)) - ++vpos2; - if (static_cast(c = row->par()->GetChar(pos)) > ' ' - && !is_nikud(c)) { - int width2 = SingleWidth(bview, row->par(), pos, c); - dx = (c == 'ø' || c == 'ã') - ? width2 - width : (width2 - width) / 2; + for (LyXParagraph::size_type i = pos-1; i >= 0; --i) { + c = row->par()->GetChar(i); + if (!Encoding::IsComposeChar_hebrew(c)) { + if (IsPrintableNonspace(c)) { + int width2 = SingleWidth(bview, row->par(), i, c); + dx = (c == 'ø' || c == 'ã') // dalet / resh + ? width2 - width : (width2 - width) / 2; + } + break; + } } // Draw nikud pain.text(int(x) + dx, offset + row->baseline(), @@ -624,8 +557,8 @@ void LyXText::draw(BufferView * bview, Row const * row, } else { while (vpos <= last && (pos = vis2log(vpos)) >= 0 - && static_cast(c = row->par()->GetChar(pos)) > ' ' - && !is_nikud(c) + && IsPrintableNonspace(c = row->par()->GetChar(pos)) + && !Encoding::IsComposeChar_hebrew(c) && font2 == GetFont(bview->buffer(), row->par(), pos)) { textstring += c; ++vpos; @@ -636,23 +569,46 @@ void LyXText::draw(BufferView * bview, Row const * row, x += lyxfont::width(textstring, font); } } else if (font.language()->lang() == "arabic" && - lyxrc.font_norm == "iso8859-6.8x") { - textstring = TransformChar(c, row->par(), pos); - while (vpos <= last && - (pos = vis2log(vpos)) >= 0 - && static_cast(c = row->par()->GetChar(pos)) > ' ' - && font2 == GetFont(bview->buffer(), row->par(), pos)) { + (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 || + lyxrc.font_norm_type == LyXRC::ISO_10646_1)) { + if (Encoding::IsComposeChar_arabic(c)) { c = TransformChar(c, row->par(), pos); - textstring += c; - ++vpos; + textstring = c; + int width = lyxfont::width(c, font2); + int dx = 0; + for (LyXParagraph::size_type i = pos-1; i >= 0; --i) { + c = row->par()->GetChar(i); + if (!Encoding::IsComposeChar_arabic(c)) { + if (IsPrintableNonspace(c)) { + int width2 = SingleWidth(bview, row->par(), i, c); + dx = (width2 - width) / 2; + } + break; + } + } + // Draw nikud + pain.text(int(x) + dx, offset + row->baseline(), + textstring, font); + } else { + textstring = TransformChar(c, row->par(), pos); + while (vpos <= last && + (pos = vis2log(vpos)) >= 0 + && IsPrintableNonspace(c = row->par()->GetChar(pos)) + && !Encoding::IsComposeChar_arabic(c) + && font2 == GetFont(bview->buffer(), row->par(), pos)) { + c = TransformChar(c, row->par(), pos); + textstring += c; + ++vpos; + } + // Draw text and set the new x position + pain.text(int(x), offset + row->baseline(), + textstring, font); + x += lyxfont::width(textstring, font); } - // Draw text and set the new x position - pain.text(int(x), offset + row->baseline(), textstring, font); - x += lyxfont::width(textstring, font); } else { while (vpos <= last && (pos = vis2log(vpos)) >= 0 - && static_cast(c = row->par()->GetChar(pos)) > ' ' + && IsPrintableNonspace(c = row->par()->GetChar(pos)) && font2 == GetFont(bview->buffer(), row->par(), pos)) { textstring += c; ++vpos; @@ -661,13 +617,8 @@ void LyXText::draw(BufferView * bview, Row const * row, pain.text(int(x), offset + row->baseline(), textstring, font); x += lyxfont::width(textstring, font); } - - // what about underbars? - if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) { - pain.line(int(tmpx), offset + row->baseline() + 2, - int(x), offset + row->baseline() + 2); - - } else if (lyxrc.mark_foreign_language && + + if (lyxrc.mark_foreign_language && font.language() != bview->buffer()->params.language_info) { int y = offset + row->height() - 1; pain.line(int(tmpx), y, int(x), y,