From 2a8a198f09f7f27df817ae417fa54d21035a2b74 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Tue, 11 Dec 2007 05:57:36 +0000 Subject: [PATCH] styles --- trunk/include/crengine.h | 2 +- trunk/include/cssdef.h | 11 ++++---- trunk/include/fb2def.h | 3 +- trunk/include/lvfntman.h | 6 ++-- trunk/include/lvtextfm.h | 40 +++++++++++++++++--------- trunk/src/lvdocview.cpp | 25 +++++++++------- trunk/src/lvfntman.cpp | 61 +++++++++++++++++++++++++++++++++------- trunk/src/lvrend.cpp | 49 ++++++++++++++++++++++++++++++-- trunk/src/lvstsheet.cpp | 2 +- trunk/src/lvtextfm.cpp | 24 +++++++++++++++- trunk/src/lvtinydom.cpp | 6 ++-- 11 files changed, 178 insertions(+), 51 deletions(-) diff --git a/trunk/include/crengine.h b/trunk/include/crengine.h index a466c043a..ec6338335 100644 --- a/trunk/include/crengine.h +++ b/trunk/include/crengine.h @@ -134,7 +134,7 @@ */ -#define CR_ENGINE_VERSION "0.4.5" +#define CR_ENGINE_VERSION "0.4.9" #include "crsetup.h" #include "lvtypes.h" diff --git a/trunk/include/cssdef.h b/trunk/include/cssdef.h index 42e18a3b8..720d1c029 100644 --- a/trunk/include/cssdef.h +++ b/trunk/include/cssdef.h @@ -74,12 +74,13 @@ enum css_vertical_align_t { /// text-decoration property values enum css_text_decoration_t { - css_td_inherit = -1, - css_td_none = 0, - css_td_underline = 1, - css_td_overline = 2, + // TODO: support multiple flags + css_td_inherit = 0, + css_td_none = 1, + css_td_underline = 2, + css_td_overline = 3, css_td_line_through = 4, - css_td_blink = 8, + css_td_blink = 5, }; /// font-style property values diff --git a/trunk/include/fb2def.h b/trunk/include/fb2def.h index 5c12f90f2..c074a5c00 100644 --- a/trunk/include/fb2def.h +++ b/trunk/include/fb2def.h @@ -78,7 +78,7 @@ XS_TAG1T( date ) XS_TAG1T( year ) XS_TAG1T( sequence ) -XS_TAG1D( stylesheet, false, css_d_none, css_ws_normal ) +XS_TAG1D( stylesheet, true, css_d_none, css_ws_normal ) XS_TAG1D( description, false, css_d_none, css_ws_normal ) XS_TAG2( title_info, "title-info" ) XS_TAG2( src_title_info, "src-title-info" ) @@ -122,6 +122,7 @@ XS_ATTR( href ) XS_ATTR( type ) XS_ATTR( mode ) XS_ATTR( price ) +XS_ATTR( style ) XS_ATTR( currency ) XS_ATTR( version ) XS_ATTR( encoding ) diff --git a/trunk/include/lvfntman.h b/trunk/include/lvfntman.h index cc17d4b33..edb671315 100644 --- a/trunk/include/lvfntman.h +++ b/trunk/include/lvfntman.h @@ -95,7 +95,7 @@ class LVFont /// draws text string virtual void DrawTextString( LVDrawBuf * buf, int x, int y, const lChar16 * text, int len, - lChar16 def_char, lUInt32 * palette, bool addHyphen ) = 0; + lChar16 def_char, lUInt32 * palette, bool addHyphen, lUInt32 flags=0 ) = 0; /// constructor LVFont() { } /// returns true if font is empty @@ -138,7 +138,7 @@ class LVBaseFont : public LVFont /// draws text string virtual void DrawTextString( LVDrawBuf * buf, int x, int y, const lChar16 * text, int len, - lChar16 def_char, lUInt32 * palette, bool addHyphen ); + lChar16 def_char, lUInt32 * palette, bool addHyphen, lUInt32 flags=0 ); }; /* C++ wrapper class */ @@ -294,7 +294,7 @@ class LVWin32DrawFont : public LVBaseWin32Font /// draws text string virtual void DrawTextString( LVDrawBuf * buf, int x, int y, const lChar16 * text, int len, - lChar16 def_char, lUInt32 * palette, bool addHyphen ); + lChar16 def_char, lUInt32 * palette, bool addHyphen, lUInt32 flags=0 ); /** \brief get glyph image in 1 byte per pixel format \param code is unicode character diff --git a/trunk/include/lvtextfm.h b/trunk/include/lvtextfm.h index 34e7c7751..ea73d8f9a 100644 --- a/trunk/include/lvtextfm.h +++ b/trunk/include/lvtextfm.h @@ -22,20 +22,28 @@ extern "C" { #endif -#define LTEXT_ALIGN_LEFT 1 /**< \brief new left-aligned paragraph */ -#define LTEXT_ALIGN_RIGHT 2 /**< \brief new right-aligned paragraph */ -#define LTEXT_ALIGN_CENTER 3 /**< \brief new centered paragraph */ -#define LTEXT_ALIGN_WIDTH 4 /**< \brief new justified paragraph */ +// text flags +#define LTEXT_ALIGN_LEFT 0x0001 /**< \brief new left-aligned paragraph */ +#define LTEXT_ALIGN_RIGHT 0x0002 /**< \brief new right-aligned paragraph */ +#define LTEXT_ALIGN_CENTER 0x0003 /**< \brief new centered paragraph */ +#define LTEXT_ALIGN_WIDTH 0x0004 /**< \brief new justified paragraph */ -#define LTEXT_FLAG_NEWLINE 7 /**< \brief new line flags mask */ -#define LTEXT_FLAG_OWNTEXT 8 /**< \brief store local copy of text instead of pointer */ +#define LTEXT_FLAG_NEWLINE 0x0007 /**< \brief new line flags mask */ +#define LTEXT_FLAG_OWNTEXT 0x0008 /**< \brief store local copy of text instead of pointer */ -#define LTEXT_VALIGN_MASK 0x70 /**< \brief vertical align flags mask */ -#define LTEXT_VALIGN_BASELINE 0x00 /**< \brief baseline vertical align */ -#define LTEXT_VALIGN_SUB 0x10 /**< \brief subscript */ -#define LTEXT_VALIGN_SUPER 0x20 /**< \brief superscript */ +#define LTEXT_VALIGN_MASK 0x0070 /**< \brief vertical align flags mask */ +#define LTEXT_VALIGN_BASELINE 0x0000 /**< \brief baseline vertical align */ +#define LTEXT_VALIGN_SUB 0x0010 /**< \brief subscript */ +#define LTEXT_VALIGN_SUPER 0x0020 /**< \brief superscript */ + +#define LTEXT_TD_UNDERLINE 0x0100 /**< \brief underlined text */ +#define LTEXT_TD_OVERLINE 0x0200 /**< \brief overlined text */ +#define LTEXT_TD_LINE_THROUGH 0x0400 /**< \brief striked through text */ +#define LTEXT_TD_BLINK 0x0800 /**< \brief blinking text */ +#define LTEXT_TD_MASK 0x0F00 /**< \brief text decoration mask */ + +#define LTEXT_SRC_IS_OBJECT 0x8000 /**< \brief superscript */ -#define LTEXT_SRC_IS_OBJECT 0x8000 /**< \brief superscript */ /** \brief Source text line @@ -58,6 +66,8 @@ typedef struct lUInt16 margin; /**< \brief first line margin */ lUInt8 interval; /**< \brief line interval, *16 (16=normal, 32=double) */ lUInt8 reserved; /**< \brief reserved */ + lUInt32 color; /**< \brief color */ + lUInt32 bgcolor; /**< \brief background color */ lUInt32 flags; /**< \brief flags */ } src_text_fragment_t; @@ -93,7 +103,7 @@ typedef struct /// object flag #define LTEXT_WORD_IS_OBJECT 0x80 -#define LTEXT_BACKGROUND_MARK_FLAGS 0xFFFF0000l +//#define LTEXT_BACKGROUND_MARK_FLAGS 0xFFFF0000l /** \brief Text formatter formatted line */ @@ -146,6 +156,8 @@ void lvtextAddSourceLine( lvfont_handle font, /* handle of font to draw string */ const lChar16 * text, /* pointer to unicode text string */ lUInt32 len, /* number of chars in text, 0 for auto(strlen) */ + lUInt32 color, /* text color */ + lUInt32 bgcolor, /* background color */ lUInt32 flags, /* flags */ lUInt8 interval, /* interline space, *16 (16=single, 32=double) */ lUInt16 margin, /* first line margin */ @@ -211,6 +223,8 @@ class LFormattedText void AddSourceLine( const lChar16 * text, /* pointer to unicode text string */ lUInt32 len, /* number of chars in text, 0 for auto(strlen) */ + lUInt32 color, /* text color */ + lUInt32 bgcolor, /* background color */ LVFont * font, /* font to draw string */ lUInt32 flags=LTEXT_ALIGN_LEFT|LTEXT_FLAG_OWNTEXT, lUInt8 interval=16, /* interline space, *16 (16=single, 32=double) */ @@ -221,7 +235,7 @@ class LFormattedText { lvtextAddSourceLine(m_pbuffer, font, //font->GetHandle() - text, len, + text, len, color, bgcolor, flags, interval, margin, object, (lUInt16)offset ); } lUInt32 Format(lUInt16 width, lUInt16 page_height) { return lvtextResize( m_pbuffer, width, page_height ); } diff --git a/trunk/src/lvdocview.cpp b/trunk/src/lvdocview.cpp index 5f33d7a26..6b2d7da62 100644 --- a/trunk/src/lvdocview.cpp +++ b/trunk/src/lvdocview.cpp @@ -396,16 +396,16 @@ void LVDocView::drawCoverTo( LVDrawBuf * drawBuf, lvRect & rc ) { if ( rc.width()<130 || rc.height()<130) return; - int base_font_size = 26; + int base_font_size = 24; int w = rc.width(); if ( w<300 ) - base_font_size = 24; + base_font_size = 22; else if ( w<500 ) - base_font_size = 28; + base_font_size = 24; else if ( w<700 ) - base_font_size = 32; + base_font_size = 26; else - base_font_size = 36; + base_font_size = 32; LVFontRef author_fnt( fontMan->GetFont( base_font_size, 600, true, css_ff_serif, lString8("Times New Roman")) ); LVFontRef title_fnt( fontMan->GetFont( base_font_size+4, 600, false, css_ff_serif, lString8("Times New Roman")) ); LVFontRef series_fnt( fontMan->GetFont( base_font_size-3, 300, true, css_ff_serif, lString8("Times New Roman")) ); @@ -416,9 +416,9 @@ void LVDocView::drawCoverTo( LVDrawBuf * drawBuf, lvRect & rc ) title = L"no title"; LFormattedText txform; if ( !authors.empty() ) - txform.AddSourceLine( authors.c_str(), authors.length(), author_fnt.get(), LTEXT_ALIGN_CENTER, 20 ); - txform.AddSourceLine( title.c_str(), title.length(), title_fnt.get(), LTEXT_ALIGN_CENTER, 20 ); - txform.AddSourceLine( series.c_str(), series.length(), series_fnt.get(), LTEXT_ALIGN_CENTER, 20 ); + txform.AddSourceLine( authors.c_str(), authors.length(), 0xFFFFFFFF, 0xFFFFFFFF, author_fnt.get(), LTEXT_ALIGN_CENTER, 20 ); + txform.AddSourceLine( title.c_str(), title.length(), 0xFFFFFFFF, 0xFFFFFFFF, title_fnt.get(), LTEXT_ALIGN_CENTER, 20 ); + txform.AddSourceLine( series.c_str(), series.length(), 0xFFFFFFFF, 0xFFFFFFFF, series_fnt.get(), LTEXT_ALIGN_CENTER, 20 ); int title_w = rc.width() - rc.width()/3; int h = txform.Format( title_w, rc.height() ) + 16; @@ -1189,7 +1189,7 @@ bool LVDocView::windowToDocPoint( lvPoint & pt ) int page_y = m_pages[page]->start; pt.x -= rc->left; pt.y -= rc->top; - CRLog::debug(" point page offset( %d, %d )", pt.x, pt.y ); + //CRLog::debug(" point page offset( %d, %d )", pt.x, pt.y ); pt.y += page_y; return true; } @@ -1208,7 +1208,7 @@ ldomXPointer LVDocView::getNodeByPoint( lvPoint pt ) { if ( windowToDocPoint( pt ) ) { ldomXPointer ptr = m_doc->createXPointer( pt ); - CRLog::debug(" ptr (%d, %d) node=%08X offset=%d", pt.x, pt.y, (lUInt32)ptr.getNode(), ptr.getOffset() ); + //CRLog::debug(" ptr (%d, %d) node=%08X offset=%d", pt.x, pt.y, (lUInt32)ptr.getNode(), ptr.getOffset() ); return ptr; } return ldomXPointer(); @@ -1678,6 +1678,11 @@ bool LVDocView::LoadDocument( LVStreamRef stream ) m_pos = 0; + lString16 docstyle = m_doc->createXPointer(L"/FictionBook/stylesheet").getText(); + if ( !docstyle.empty() ) { + m_doc->getStyleSheet()->parse(UnicodeToUtf8(docstyle).c_str()); + } + #if 0 { LVStreamRef ostream = LVOpenFileStream( "test_save.fb2", LVOM_WRITE ); diff --git a/trunk/src/lvfntman.cpp b/trunk/src/lvfntman.cpp index 08e51f4f3..309e7430e 100644 --- a/trunk/src/lvfntman.cpp +++ b/trunk/src/lvfntman.cpp @@ -256,14 +256,34 @@ struct LVFontGlyphCacheItem return sizeof(LVFontGlyphCacheItem) + (bmp_width * bmp_height - 1) * sizeof(lUInt8); } - static LVFontGlyphCacheItem * newItem( LVFontLocalGlyphCache * local_cache, lChar16 ch, FT_GlyphSlot slot ) + static LVFontGlyphCacheItem * newItem( LVFontLocalGlyphCache * local_cache, lChar16 ch, FT_GlyphSlot slot, bool drawMonochrome ) { FT_Bitmap* bitmap = &slot->bitmap; lUInt8 w = (lUInt8)(bitmap->width); lUInt8 h = (lUInt8)(bitmap->rows); LVFontGlyphCacheItem * item = (LVFontGlyphCacheItem *)malloc( sizeof(LVFontGlyphCacheItem) + (w*h - 1)*sizeof(lUInt8) ); - memcpy( item->bmp, bitmap->buffer, w*h ); + if ( drawMonochrome ) { + lUInt8 mask = 0x80; + const lUInt8 * ptr = (const lUInt8 *)bitmap->buffer; + lUInt8 * dst = item->bmp; + int rowsize = ((w + 15) / 16) * 2; + for ( int y=0; y>= 1; + if ( !mask && x!=w-1) { + mask = 0x80; + row++; + } + } + ptr += rowsize; + } + } else { + memcpy( item->bmp, bitmap->buffer, w*h ); + } item->ch = ch; item->bmp_width = w; item->bmp_height = h; @@ -406,10 +426,11 @@ class LVFreeTypeFace : public LVFont int _baseline; LVFontGlyphWidthCache _wcache; LVFontLocalGlyphCache _glyph_cache; + bool _drawMonochrome; public: LVFreeTypeFace( FT_Library library, LVFontGlobalGlyphCache * globalCache ) : _fontFamily(css_ff_sans_serif), _library(library), _face(NULL), _size(0), _hyphen_width(0), _baseline(0) - , _glyph_cache(globalCache) + , _glyph_cache(globalCache), _drawMonochrome(false) { } @@ -418,8 +439,9 @@ class LVFreeTypeFace : public LVFont Clear(); } - bool loadFromFile( const char * fname, int index, int size, css_font_family_t fontFamily ) + bool loadFromFile( const char * fname, int index, int size, css_font_family_t fontFamily, bool monochrome ) { + _drawMonochrome = monochrome; _fontFamily = fontFamily; if ( fname ) _fileName = fname; @@ -676,7 +698,7 @@ class LVFreeTypeFace : public LVFont /// draws text string virtual void DrawTextString( LVDrawBuf * buf, int x, int y, const lChar16 * text, int len, - lChar16 def_char, lUInt32 * palette, bool addHyphen ) + lChar16 def_char, lUInt32 * palette, bool addHyphen, lUInt32 flags ) { if ( len <= 0 || _face==NULL ) return; @@ -697,6 +719,7 @@ class LVFreeTypeFace : public LVFont lChar16 ch; // measure character widths bool isHyphen = false; + int x0 = x; for ( i=0; i<=len; i++) { if ( i==len && (!addHyphen || isHyphen) ) break; @@ -726,15 +749,16 @@ class LVFreeTypeFace : public LVFont LVFontGlyphCacheItem * item = _glyph_cache.get( ch ); if ( !item ) { + int rend_flags = FT_LOAD_RENDER | ( !_drawMonochrome ? FT_LOAD_TARGET_NORMAL : (FT_LOAD_TARGET_MONO) ); //|FT_LOAD_MONOCHROME|FT_LOAD_FORCE_AUTOHINT /* load glyph image into the slot (erase previous one) */ error = FT_Load_Glyph( _face, /* handle to face object */ ch_glyph_index, /* glyph index */ - FT_LOAD_RENDER ); /* load flags, see below */ + rend_flags ); /* load flags, see below */ if ( error ) { continue; /* ignore errors */ } - item = LVFontGlyphCacheItem::newItem( &_glyph_cache, ch, _slot ); + item = LVFontGlyphCacheItem::newItem( &_glyph_cache, ch, _slot, _drawMonochrome ); _glyph_cache.put( item ); } if ( item && !isHyphen || i>=len-1 ) { // avoid soft hyphens inside text string @@ -750,6 +774,23 @@ class LVFreeTypeFace : public LVFont previous = ch_glyph_index; } } + if ( flags & LTEXT_TD_MASK ) { + // text decoration: underline, etc. + int h = _size > 30 ? 2 : 1; + lUInt32 cl = buf->GetTextColor(); + if ( flags & LTEXT_TD_UNDERLINE || flags & LTEXT_TD_BLINK ) { + int liney = y + _baseline + h; + buf->FillRect( x0, liney, x, liney+h, cl ); + } + if ( flags & LTEXT_TD_OVERLINE ) { + int liney = y + h; + buf->FillRect( x0, liney, x, liney+h, cl ); + } + if ( flags & LTEXT_TD_LINE_THROUGH ) { + int liney = y + _size/2 - h/2; + buf->FillRect( x0, liney, x, liney+h, cl ); + } + } } /// returns true if font is empty @@ -888,7 +929,7 @@ class LVFreeTypeFontManager : public LVFontManager //} //printf("going to load font file %s\n", fname.c_str()); - if (font->loadFromFile( pathname.c_str(), item->getDef()->getIndex(), size, family ) ) + if (font->loadFromFile( pathname.c_str(), item->getDef()->getIndex(), size, family, false ) ) { //fprintf(_log, " : loading from file %s : %s %d\n", item->getDef()->getName().c_str(), // item->getDef()->getTypeFace().c_str(), item->getDef()->getSize() ); @@ -1380,7 +1421,7 @@ int LVFontDef::CalcMatch( const LVFontDef & def ) const void LVBaseFont::DrawTextString( LVDrawBuf * buf, int x, int y, const lChar16 * text, int len, - lChar16 def_char, lUInt32 * palette, bool addHyphen ) + lChar16 def_char, lUInt32 * palette, bool addHyphen, lUInt32 flags ) { static lUInt8 glyph_buf[16384]; LVFont::glyph_info_t info; @@ -1877,7 +1918,7 @@ lUInt16 LVWin32DrawFont::measureText( /// draws text string void LVWin32DrawFont::DrawTextString( LVDrawBuf * buf, int x, int y, const lChar16 * text, int len, - lChar16 def_char, lUInt32 * palette, bool addHyphen ) + lChar16 def_char, lUInt32 * palette, bool addHyphen, lUInt32 flags ) { if (_hfont==NULL) return; diff --git a/trunk/src/lvrend.cpp b/trunk/src/lvrend.cpp index 9fb943398..15880103f 100644 --- a/trunk/src/lvrend.cpp +++ b/trunk/src/lvrend.cpp @@ -349,6 +349,22 @@ void renderFinalBlock( ldomNode * node, LFormattedText * txform, lvdomElementFor default: break; } + switch ( enode->getStyle()->text_decoration ) { + case css_td_underline: + flags |= LTEXT_TD_UNDERLINE; + break; + case css_td_overline: + flags |= LTEXT_TD_OVERLINE; + break; + case css_td_line_through: + flags |= LTEXT_TD_LINE_THROUGH; + break; + case css_td_blink: + flags |= LTEXT_TD_BLINK; + break; + default: + break; + } const elem_def_t * ntype = node->getElementTypePtr(); if ( ntype && ntype->props.is_object ) { @@ -408,8 +424,12 @@ void renderFinalBlock( ldomNode * node, LFormattedText * txform, lvdomElementFor << baseflags << ")\n"; #endif - LVFont * font = ((ldomElement*)node->getParentNode())->getFont().get(); - txform->AddSourceLine( txt.c_str(), txt.length(), font, baseflags | LTEXT_FLAG_OWNTEXT, line_h, ident, node ); + ldomElement * parent = ((ldomElement*)node->getParentNode()); + LVFont * font = parent->getFont().get(); + css_style_ref_t style = parent->getStyle(); + lUInt32 cl = style->color.type!=css_val_color ? 0xFFFFFFFF : style->color.value; + lUInt32 bgcl = style->background_color.type!=css_val_color ? 0xFFFFFFFF : style->background_color.value; + txform->AddSourceLine( txt.c_str(), txt.length(), cl, bgcl, font, baseflags | LTEXT_FLAG_OWNTEXT, line_h, ident, node ); baseflags &= ~LTEXT_FLAG_NEWLINE; // clear newline flag } } @@ -480,7 +500,7 @@ int renderBlockElement( LVRendPageContext & context, ldomNode * node, int x, int int st_y = lengthToPx( enode->getStyle()->height, em, em ); if ( y < st_y ) y = st_y; - fmt->setHeight( y ); + fmt->setHeight( y ); //+ margin_top + margin_bottom ); //??? return y + margin_top + margin_bottom; // return block height } break; @@ -549,6 +569,13 @@ void DrawDocument( LVDrawBuf & drawbuf, ldomNode * node, int x0, int y0, int dx, { return; // out of range } + css_length_t bg = enode->getStyle()->background_color; + lUInt32 oldColor; + if ( bg.type==css_val_color ) { + oldColor = drawbuf.GetBackgroundColor(); + drawbuf.SetBackgroundColor( bg.value ); + drawbuf.FillRect( x0 + doc_x, y0 + doc_y, x0 + doc_x+fmt->getWidth(), y0+doc_y+fmt->getHeight(), bg.value ); + } #if (DEBUG_TREE_DRAW!=0) lUInt32 color; if (drawbuf.GetBitsPerPixel()>=16) @@ -610,6 +637,9 @@ void DrawDocument( LVDrawBuf & drawbuf, ldomNode * node, int x0, int y0, int dx, default: crFatalError(); // error } + if ( bg.type==css_val_color ) { + drawbuf.SetBackgroundColor( oldColor ); + } } } @@ -668,6 +698,19 @@ void setNodeStyle( ldomNode * node, css_style_ref_t parent_style, LVFontRef pare // apply style sheet ////////////////////////////////////////////////////// node->getDocument()->getStyleSheet()->apply( node, pstyle ); + + if ( enode->hasAttribute( LXML_NS_ANY, attr_style ) ) { + lString16 nodeStyle = enode->getAttributeValue( LXML_NS_ANY, attr_style ); + if ( !nodeStyle.empty() ) { + nodeStyle = lString16(L"{") + nodeStyle + L"}"; + LVCssDeclaration decl; + lString8 s8 = UnicodeToUtf8(nodeStyle); + const char * s = s8.c_str(); + if ( decl.parse( s ) ) { + decl.apply( pstyle ); + } + } + } /* switch ( node->getNodeId() ) { diff --git a/trunk/src/lvstsheet.cpp b/trunk/src/lvstsheet.cpp index 38aafd125..176563a22 100644 --- a/trunk/src/lvstsheet.cpp +++ b/trunk/src/lvstsheet.cpp @@ -276,7 +276,7 @@ static bool parse_color_value( const char * & str, css_length_t & value ) // #rgb or #rrggbb colors str++; int nDigits = 0; - for ( ; hexDigit(str[nDigits]); nDigits++ ) + for ( ; hexDigit(str[nDigits])>=0; nDigits++ ) ; if ( nDigits==3 ) { int r = hexDigit( *str++ ); diff --git a/trunk/src/lvtextfm.cpp b/trunk/src/lvtextfm.cpp index d68db3374..98b2bb133 100644 --- a/trunk/src/lvtextfm.cpp +++ b/trunk/src/lvtextfm.cpp @@ -115,6 +115,8 @@ void lvtextAddSourceLine( formatted_text_fragment_t * pbuffer, lvfont_handle font, /* handle of font to draw string */ const lChar16 * text, /* pointer to unicode text string */ lUInt32 len, /* number of chars in text, 0 for auto(strlen) */ + lUInt32 color, /* color */ + lUInt32 bgcolor, /* bgcolor */ lUInt32 flags, /* flags */ lUInt8 interval, /* interline space, *16 (16=single, 32=double) */ lUInt16 margin, /* first line margin */ @@ -147,6 +149,8 @@ void lvtextAddSourceLine( formatted_text_fragment_t * pbuffer, pline->flags = flags; pline->interval = interval; pline->t.offset = offset; + pline->color = color; + pline->bgcolor = bgcolor; } void lvtextAddSourceObject( @@ -642,6 +646,11 @@ void LFormattedText::Draw( LVDrawBuf * buf, int x, int y, ldomMarkedRangeList * frmline = m_pbuffer->frmlines[i]; if (line_y + frmline->height>=clip.top) { + // process background + + lUInt32 bgcl = buf->GetBackgroundColor(); + buf->FillRect( x+frmline->x, y + frmline->y, x+frmline->x + frmline->width, y + frmline->y + frmline->height, bgcl ); + // process marks if ( marks!=NULL && marks->length()>0 ) { lvRect lineRect( frmline->x, frmline->y, frmline->x + frmline->width, frmline->y + frmline->height ); @@ -689,6 +698,14 @@ void LFormattedText::Draw( LVDrawBuf * buf, int x, int y, ldomMarkedRangeList * buf->FillRect( rc.left, rc.top, rc.right, rc.bottom, 0xAAAAAA ); } */ + lUInt32 oldColor = buf->GetTextColor(); + lUInt32 oldBgColor = buf->GetBackgroundColor(); + lUInt32 cl = srcline->color; + lUInt32 bgcl = srcline->bgcolor; + if ( cl!=0xFFFFFFFF ) + buf->SetTextColor( cl ); + if ( bgcl!=0xFFFFFFFF ) + buf->SetBackgroundColor( bgcl ); font->DrawTextString( buf, x + frmline->x + word->x, @@ -697,7 +714,12 @@ void LFormattedText::Draw( LVDrawBuf * buf, int x, int y, ldomMarkedRangeList * word->t.len, '?', NULL, - flgHyphen); + flgHyphen, + srcline->flags & 0x0F00); + if ( cl!=0xFFFFFFFF ) + buf->SetTextColor( oldColor ); + if ( bgcl!=0xFFFFFFFF ) + buf->SetBackgroundColor( oldBgColor ); } } } diff --git a/trunk/src/lvtinydom.cpp b/trunk/src/lvtinydom.cpp index da2f4d69d..7069b91a4 100644 --- a/trunk/src/lvtinydom.cpp +++ b/trunk/src/lvtinydom.cpp @@ -1431,7 +1431,7 @@ ldomXPointer ldomDocument::createXPointer( lvPoint pt ) return ptr; lvRect rc; finalNode->getAbsRect( rc ); - CRLog::debug("ldomDocument::createXPointer point = (%d, %d), finalNode %08X rect = (%d,%d,%d,%d)", pt.x, pt.y, (lUInt32)finalNode, rc.left, rc.top, rc.right, rc.bottom ); + //CRLog::debug("ldomDocument::createXPointer point = (%d, %d), finalNode %08X rect = (%d,%d,%d,%d)", pt.x, pt.y, (lUInt32)finalNode, rc.left, rc.top, rc.right, rc.bottom ); pt.x -= rc.left; pt.y -= rc.top; lvdomElementFormatRec * r = finalNode->getRenderData(); @@ -1452,7 +1452,7 @@ ldomXPointer ldomDocument::createXPointer( lvPoint pt ) const formatted_line_t * frmline = txtform.GetLineInfo(l); if ( pt.y >= (int)(frmline->y + frmline->height) && ly, frmline->y+frmline->height); + //CRLog::debug(" point (%d, %d) line found [%d]: (%d..%d)", pt.x, pt.y, l, frmline->y, frmline->y+frmline->height); // found line, searching for word int wc = (int)frmline->word_count; int x = pt.x - frmline->x; @@ -1460,7 +1460,7 @@ ldomXPointer ldomDocument::createXPointer( lvPoint pt ) const formatted_word_t * word = &frmline->words[w]; if ( x < word->x + word->width || w==wc-1 ) { const src_text_fragment_t * src = txtform.GetSrcInfo(word->src_text_index); - CRLog::debug(" word found [%d]: x=%d..%d, start=%d, len=%d %08X", w, word->x, word->x + word->width, word->t.start, word->t.len, src->object); + //CRLog::debug(" word found [%d]: x=%d..%d, start=%d, len=%d %08X", w, word->x, word->x + word->width, word->t.start, word->t.len, src->object); // found word, searching for letters ldomNode * node = (ldomNode *)src->object; if ( src->flags & LTEXT_SRC_IS_OBJECT ) {