20#include "KoTextFormat.h"
21#include "KoTextParag.h"
22#include "KoTextZoomHandler.h"
23#include "KoStyleCollection.h"
24#include "KoOasisContext.h"
25#include <KoGenStyles.h>
32#include <tqapplication.h>
36void KoTextFormat::KoTextFormatPrivate::clearCache()
38 delete m_screenFontMetrics; m_screenFontMetrics = 0L;
39 delete m_screenFont; m_screenFont = 0L;
40 delete m_refFontMetrics; m_refFontMetrics = 0L;
41 delete m_refFont; m_refFont = 0L;
45 memset( m_screenWidths, 0, 256 *
sizeof( ushort ) );
50 delete d->m_screenFontMetrics; d->m_screenFontMetrics = 0;
51 delete d->m_screenFont; d->m_screenFont = 0;
52 memset( d->m_screenWidths, 0, 256 *
sizeof( ushort ) );
55KoTextFormat::KoTextFormat()
63 fn.setStyleStrategy( TQFont::ForceOutline );
64 d =
new KoTextFormatPrivate;
65 m_textUnderlineColor=TQColor();
66 m_underlineType = U_NONE;
67 m_strikeOutType = S_NONE;
68 m_underlineStyle = U_SOLID;
69 m_strikeOutStyle = S_SOLID;
70 m_language = TDEGlobal::locale()->language();
71 d->m_bHyphenation =
false;
72 d->m_underLineWidth = 1.0;
73 d->m_shadowDistanceX = 0;
74 d->m_shadowDistanceY = 0;
75 d->m_relativeTextSize = 0.66;
76 d->m_offsetFromBaseLine= 0;
77 d->m_bWordByWord =
false;
78 m_attributeFont = ATT_NONE;
85KoTextFormat::KoTextFormat(
const TQFont &f,
const TQColor &c,
const TQString &_language,
bool hyphenation, KoTextFormatCollection *parent )
88#ifdef DEBUG_COLLECTION
89 kdDebug(32500) <<
"KoTextFormat with font & color & parent (" << parent <<
"), addRef. " <<
this << endl;
92 if ( f.pointSize() == -1 )
93 pointSize = (int)( ( (
double)fn.pixelSize() * 72.0 ) / (double)KoGlobal::dpiY() );
95 pointSize = f.pointSize();
96 fn.setPointSize( pointSize );
98 fn.setStyleStrategy( TQFont::ForceOutline );
109 d =
new KoTextFormatPrivate;
110 m_textUnderlineColor = TQColor();
111 m_underlineType = U_NONE;
112 m_strikeOutType = S_NONE;
113 m_underlineStyle = U_SOLID;
114 m_strikeOutStyle = S_SOLID;
115 m_language = _language;
116 d->m_shadowDistanceX = 0;
117 d->m_shadowDistanceY = 0;
118 d->m_relativeTextSize= 0.66;
119 d->m_offsetFromBaseLine = 0;
120 d->m_bWordByWord =
false;
122 d->m_bHyphenation = hyphenation;
123 d->m_underLineWidth = 1.0;
124 m_attributeFont = ATT_NONE;
130KoTextFormat::KoTextFormat(
const TQFont &_font,
131 VerticalAlignment _valign,
132 const TQColor & _color,
133 const TQColor & _backGroundColor,
134 const TQColor & _underlineColor,
135 KoTextFormat::UnderlineType _underlineType,
136 KoTextFormat::UnderlineStyle _underlineStyle,
137 KoTextFormat::StrikeOutType _strikeOutType,
138 KoTextFormat::StrikeOutStyle _strikeOutStyle,
139 KoTextFormat::AttributeStyle _fontAttribute,
140 const TQString &_language,
141 double _relativeTextSize,
142 int _offsetFromBaseLine,
145 double _shadowDistanceX,
146 double _shadowDistanceY,
147 const TQColor& _shadowColor )
152 fn.setStyleStrategy( TQFont::ForceOutline );
156 d =
new KoTextFormatPrivate;
157 m_textBackColor = _backGroundColor;
158 m_textUnderlineColor = _underlineColor;
159 m_underlineType = _underlineType;
160 m_strikeOutType = _strikeOutType;
161 m_underlineStyle = _underlineStyle;
162 m_strikeOutStyle = _strikeOutStyle;
163 m_language = _language;
164 d->m_bHyphenation = _hyphenation;
165 d->m_underLineWidth = 1.0;
166 d->m_shadowDistanceX = _shadowDistanceX;
167 d->m_shadowDistanceY = _shadowDistanceY;
168 d->m_shadowColor = _shadowColor;
169 d->m_relativeTextSize = _relativeTextSize;
170 d->m_offsetFromBaseLine = _offsetFromBaseLine;
171 d->m_bWordByWord = _wordByWord;
172 m_attributeFont = _fontAttribute;
185KoTextFormat::~KoTextFormat()
191 if ( parent() && parent()->defaultFormat() )
192 assert( ! ( parent()->dict().
find( key() ) ==
this ) );
201#ifdef DEBUG_COLLECTION
202 kdDebug(32500) <<
"KoTextFormat::operator= " <<
this <<
" (copying " << &f <<
"). Will addRef" << endl;
220 d =
new KoTextFormatPrivate;
221 m_textBackColor=f.m_textBackColor;
222 m_textUnderlineColor=f.m_textUnderlineColor;
223 m_underlineType = f.m_underlineType;
224 m_strikeOutType = f.m_strikeOutType;
225 m_underlineStyle = f.m_underlineStyle;
226 m_strikeOutStyle = f.m_strikeOutStyle;
227 m_language = f.m_language;
228 d->m_bHyphenation=f.d->m_bHyphenation;
229 d->m_underLineWidth=f.d->m_underLineWidth;
230 d->m_shadowDistanceX = f.d->m_shadowDistanceX;
231 d->m_shadowDistanceY = f.d->m_shadowDistanceY;
232 d->m_shadowColor = f.d->m_shadowColor;
233 d->m_relativeTextSize = f.d->m_relativeTextSize;
234 d->m_offsetFromBaseLine = f.d->m_offsetFromBaseLine;
235 d->m_bWordByWord = f.d->m_bWordByWord;
236 m_attributeFont = f.m_attributeFont;
244static void importTextPosition(
const TQString& text_position,
double fontSize, KoTextFormat::VerticalAlignment& value,
double& relativetextsize,
int& offset,
KoOasisContext& context )
248 TQStringList lst = TQStringList::split(
' ', text_position );
249 if ( !lst.isEmpty() )
251 TQString textPos = lst.front().stripWhiteSpace();
254 if ( !lst.isEmpty() )
255 textSize = lst.front().stripWhiteSpace();
257 if ( context.
generator().startsWith(
"KOffice/1.4" )
258 && text_position.startsWith(
"0%" ) ) {
260 value = KoTextFormat::AlignNormal;
264 if ( textPos.endsWith(
"%") && textPos !=
"0% 100%" && textPos !=
"0%" )
266 textPos.truncate( textPos.length() - 1 );
267 double val = textPos.toDouble();
268 offset = tqRound( fontSize * val / 100.0 );
269 value = KoTextFormat::AlignCustom;
271 else if ( textPos ==
"super" )
272 value = KoTextFormat::AlignSuperScript;
273 else if ( textPos ==
"sub" )
274 value = KoTextFormat::AlignSubScript;
276 value = KoTextFormat::AlignNormal;
277 if ( !textSize.isEmpty() && textSize.endsWith(
"%") )
279 textSize.truncate( textSize.length() - 1 );
280 relativetextsize = textSize.toDouble() / 100;
284 value = KoTextFormat::AlignNormal;
288static void importOasisUnderline(
const TQString& type,
const TQString& style,
289 KoTextFormat::UnderlineType& underline,
290 KoTextFormat::UnderlineStyle& styleline )
292 if ( type ==
"single" )
293 underline = KoTextFormat::U_SIMPLE;
294 else if ( type ==
"double" )
295 underline = KoTextFormat::U_DOUBLE;
296 else if ( type ==
"none" )
297 underline = KoTextFormat::U_NONE;
298 else if ( style.isEmpty() || style ==
"none" )
299 underline = KoTextFormat::U_NONE;
301 underline = KoTextFormat::U_SIMPLE;
303 styleline = KoTextFormat::U_SOLID;
304 if ( style ==
"dotted" )
305 styleline = KoTextFormat::U_DOT;
306 else if ( style ==
"dash"
307 || style ==
"long-dash" )
308 styleline = KoTextFormat::U_DASH;
309 else if ( style ==
"dot-dash" )
310 styleline = KoTextFormat::U_DASH_DOT;
311 else if ( style ==
"dot-dot-dash" )
312 styleline = KoTextFormat::U_DASH_DOT_DOT;
313 else if ( style ==
"wave" )
314 underline = KoTextFormat::U_WAVE;
320TQString exportOasisUnderline( KoTextFormat::UnderlineStyle styleline )
322 switch( styleline ) {
323 case KoTextFormat::U_DOT:
325 case KoTextFormat::U_DASH:
327 case KoTextFormat::U_DASH_DOT:
329 case KoTextFormat::U_DASH_DOT_DOT:
330 return "dot-dot-dash";
337static void importUnderline(
const TQString& in,
338 KoTextFormat::UnderlineType& underline,
339 KoTextFormat::UnderlineStyle& styleline )
341 underline = KoTextFormat::U_SIMPLE;
342 styleline = KoTextFormat::U_SOLID;
344 underline = KoTextFormat::U_NONE;
345 else if ( in ==
"single" )
346 styleline = KoTextFormat::U_SOLID;
347 else if ( in ==
"double" ) {
348 underline = KoTextFormat::U_DOUBLE;
350 else if ( in ==
"dotted" || in ==
"bold-dotted" )
351 styleline = KoTextFormat::U_DOT;
352 else if ( in ==
"dash"
356 || in ==
"bold-long-dash" )
357 styleline = KoTextFormat::U_DASH;
358 else if ( in ==
"dot-dash"
359 || in ==
"bold-dot-dash")
360 styleline = KoTextFormat::U_DASH_DOT;
361 else if ( in ==
"dot-dot-dash"
362 || in ==
"bold-dot-dot-dash")
363 styleline = KoTextFormat::U_DASH_DOT_DOT;
364 else if ( in ==
"wave"
366 || in ==
"double-wave"
367 || in ==
"small-wave" ) {
368 underline = KoTextFormat::U_WAVE;
369 }
else if( in ==
"bold" ) {
370 underline = KoTextFormat::U_SIMPLE_BOLD;
372 kdWarning() << k_funcinfo <<
" unsupported text-underline value: " << in << endl;
381 col.setNamedColor( styleStack.
attributeNS( KoXmlNS::fo,
"color" ) );
386 TQString fontName = styleStack.
attributeNS( KoXmlNS::fo,
"font-family" ).remove(
"'" );
387 if (fontName.isEmpty()) {
390 fontName = styleStack.
attributeNS( KoXmlNS::style,
"font-name" ).remove(
"'" );
394 if ( fontName ==
"Thorndale" )
395 fontName =
"Times New Roman";
397 fontName.remove(TQRegExp(
"\\sCE$"));
398 fn.setFamily( fontName );
401 double pointSize = styleStack.
fontSize();
402 fn.setPointSizeFloat( pointSize );
405 TQString fontWeight = styleStack.
attributeNS( KoXmlNS::fo,
"font-weight" );
407 if ( fontWeight ==
"normal" )
409 else if ( fontWeight ==
"bold" )
414 boldness = fontWeight.toInt() / 10;
415 fn.setWeight( boldness );
418 if ( styleStack.
attributeNS( KoXmlNS::fo,
"font-style" ) ==
"italic" ||
419 styleStack.
attributeNS( KoXmlNS::fo,
"font-style" ) ==
"oblique" ) {
420 fn.setItalic(
true );
423 d->m_bWordByWord = styleStack.
attributeNS( KoXmlNS::style,
"text-underline-mode" ) ==
"skip-white-space";
427 d->m_bWordByWord = (styleStack.
hasAttributeNS( KoXmlNS::fo,
"score-spaces"))
428 && (styleStack.
attributeNS( KoXmlNS::fo,
"score-spaces") ==
"false");
429 if( styleStack.
hasAttributeNS( KoXmlNS::style,
"text-crossing-out" )) {
430 TQString strikeOutType = styleStack.
attributeNS( KoXmlNS::style,
"text-crossing-out" );
431 if( strikeOutType ==
"double-line")
432 m_strikeOutType = S_DOUBLE;
433 else if( strikeOutType ==
"single-line")
434 m_strikeOutType = S_SIMPLE;
435 else if( strikeOutType ==
"thick-line")
436 m_strikeOutType = S_SIMPLE_BOLD;
441 if ( styleStack.
hasAttributeNS( KoXmlNS::style,
"text-underline-type" )
442 || styleStack.
hasAttributeNS( KoXmlNS::style,
"text-underline-style" ) ) {
443 importOasisUnderline( styleStack.
attributeNS( KoXmlNS::style,
"text-underline-type" ),
444 styleStack.
attributeNS( KoXmlNS::style,
"text-underline-style" ),
445 m_underlineType, m_underlineStyle );
447 else if ( styleStack.
hasAttributeNS( KoXmlNS::style,
"text-underline" ) ) {
448 importUnderline( styleStack.
attributeNS( KoXmlNS::style,
"text-underline" ),
449 m_underlineType, m_underlineStyle );
451 TQString underLineColor = styleStack.
attributeNS( KoXmlNS::style,
"text-underline-color" );
452 if ( !underLineColor.isEmpty() && underLineColor !=
"font-color" )
453 m_textUnderlineColor.setNamedColor( underLineColor );
455 if ( styleStack.
hasAttributeNS( KoXmlNS::style,
"text-line-through-type" ) ) {
457 UnderlineType uType; UnderlineStyle uStyle;
458 importOasisUnderline( styleStack.
attributeNS( KoXmlNS::style,
"text-line-through-type" ),
459 styleStack.
attributeNS( KoXmlNS::style,
"text-line-through-style" ),
461 m_strikeOutType = S_NONE;
462 if ( uType != U_WAVE )
463 m_strikeOutType = (StrikeOutType)uType;
464 m_strikeOutStyle = (StrikeOutStyle)uStyle;
469 d->m_relativeTextSize = 0.58;
470 d->m_offsetFromBaseLine = 0;
471 if( styleStack.
hasAttributeNS( KoXmlNS::style,
"text-position")) {
472 importTextPosition( styleStack.
attributeNS( KoXmlNS::style,
"text-position"), fn.pointSizeFloat(),
473 va, d->m_relativeTextSize, d->m_offsetFromBaseLine, context );
476 m_attributeFont = ATT_NONE;
479 bool smallCaps = styleStack.
attributeNS( KoXmlNS::fo,
"font-variant" ) ==
"small-caps";
481 m_attributeFont = ATT_SMALL_CAPS;
483 TQString textTransform = styleStack.
attributeNS( KoXmlNS::fo,
"text-transform" );
484 if ( textTransform ==
"uppercase" )
485 m_attributeFont = ATT_UPPER;
486 else if ( textTransform ==
"lowercase" )
487 m_attributeFont = ATT_LOWER;
492 m_language = styleStack.
attributeNS( KoXmlNS::fo,
"language");
493 const TQString country = styleStack.
attributeNS( KoXmlNS::fo,
"country" );
494 if ( !country.isEmpty() ) {
496 m_language += country;
499 if ( styleStack.
hasAttributeNS( KoXmlNS::fo,
"background-color") ) {
500 TQString tmp = styleStack.
attributeNS( KoXmlNS::fo,
"background-color");
501 if (tmp !=
"transparent")
502 m_textBackColor.setNamedColor( tmp );
508 d->m_bHyphenation =
true;
510 d->m_bHyphenation = styleStack.
attributeNS( KoXmlNS::fo,
"hyphenate" ) ==
"true";
535 d->m_underLineWidth = 1.0;
544 if ( !refFormat || this->color() != refFormat->color() )
546 gs.
addProperty(
"fo:color", col.isValid() ? col.name() :
"#000000", tt );
548 if ( !refFormat || this->font().family() != refFormat->font().family() )
550 gs.
addProperty(
"style:font-name", fn.family(), tt );
551 context.addFontFace( fn.family() );
553 if ( !refFormat || this->pointSize() != refFormat->pointSize() )
558 if ( !refFormat || w != refFormat->font().weight() )
560 gs.
addProperty(
"fo:font-weight", w == 50 ?
"normal" : w == 75 ?
"bold" : TQString::number( tqRound( w / 10 ) * 100 ), tt );
562 if ( !refFormat || this->font().italic() != refFormat->font().italic() )
564 gs.
addProperty(
"fo:font-style", fn.italic() ?
"italic" :
"normal", tt );
566 if ( !refFormat || this->wordByWord() != refFormat->wordByWord() )
568 gs.
addProperty(
"style:text-underline-mode", d->m_bWordByWord ?
"skip-white-space" :
"continuous", tt );
570 if ( !refFormat || this->underlineType() != refFormat->underlineType()
571 || this->underlineStyle() !=refFormat->underlineStyle() )
573 gs.
addProperty(
"style:text-underline-type", m_underlineType == U_NONE ?
"none" :
574 m_underlineType == U_DOUBLE ?
"double" :
"single", tt );
576 if ( m_underlineType == U_WAVE )
579 styleline = exportOasisUnderline( m_underlineStyle );
580 gs.
addProperty(
"style:text-underline-style", m_underlineType == U_NONE ?
"none" : styleline, tt );
582 if ( !refFormat || this->textUnderlineColor() !=refFormat->textUnderlineColor() )
584 gs.
addProperty(
"style:text-underline-color", m_textUnderlineColor.isValid() ? m_textUnderlineColor.name() :
"font-color", tt );
588 || this->strikeOutType() != refFormat->strikeOutType()
589 || this->strikeOutStyle()!= refFormat->strikeOutStyle() )
591 if ( m_strikeOutType != S_NONE )
595 gs.
addProperty(
"style:text-line-through-type", m_strikeOutType == S_DOUBLE ?
"double" :
"single", tt );
596 const TQString styleline = exportOasisUnderline( (UnderlineStyle) m_strikeOutStyle );
597 gs.
addProperty(
"style:text-line-through-style", styleline, tt );
602 gs.
addProperty(
"style:text-line-through-type",
"none", tt );
603 gs.
addProperty(
"style:text-line-through-style",
"none", tt );
606 if ( !refFormat || (this->vAlign() != refFormat->vAlign())
607 || (this->relativeTextSize() != refFormat->relativeTextSize()) )
610 if ( d->m_offsetFromBaseLine != 0 )
611 textPos = TQString::number( 100 * d->m_offsetFromBaseLine / fn.pointSizeFloat() ) +
'%';
612 else if ( va == AlignSuperScript ) textPos =
"super";
613 else if ( va == AlignSubScript ) textPos =
"sub";
615 if ( va != AlignNormal )
618 textPos += TQString::number( d->m_relativeTextSize * 100 );
621 gs.
addProperty(
"style:text-position", textPos, tt );
624 if( !refFormat || this->attributeFont() != refFormat->attributeFont())
626 if ( m_attributeFont == ATT_SMALL_CAPS ) {
627 gs.
addProperty(
"fo:font-variant",
"small-caps", tt );
630 else if ( m_attributeFont == ATT_UPPER ) {
632 gs.
addProperty(
"fo:text-transform",
"uppercase", tt );
634 else if ( m_attributeFont == ATT_LOWER ) {
636 gs.
addProperty(
"fo:text-transform",
"lowercase", tt );
644 if( !refFormat || this->language() != refFormat->language())
646 TQString lang = m_language;
648 const int pos = lang.find(
'_' );
650 country = lang.mid( pos + 1 );
651 lang = lang.left( pos );
657 if( !refFormat || this->textBackgroundColor() != refFormat->textBackgroundColor() )
660 m_textBackColor.isValid() ? m_textBackColor.name() :
"transparent", tt );
663 ( this->shadowDistanceX() != refFormat->shadowDistanceX()
664 || ( this->shadowDistanceY() != refFormat->shadowDistanceY() )
665 || ( this->shadowColor() != refFormat->shadowColor() ) ) )
669 if ( !refFormat || this->hyphenation() != refFormat->hyphenation() )
671 gs.
addProperty(
"fo:hyphenate", d->m_bHyphenation, tt );
675void KoTextFormat::update()
683void KoTextFormat::copyFormat(
const KoTextFormat & nf,
int flags )
685 if ( flags & KoTextFormat::Bold )
686 fn.setBold( nf.fn.bold() );
687 if ( flags & KoTextFormat::Italic )
688 fn.setItalic( nf.fn.italic() );
689 if ( flags & KoTextFormat::Underline )
690 fn.setUnderline( nf.fn.underline() );
691 if ( flags & KoTextFormat::Family )
692 fn.setFamily( nf.fn.family() );
693 if ( flags & KoTextFormat::Size )
694 fn.setPointSize( nf.fn.pointSize() );
695 if ( flags & KoTextFormat::Color )
697 if ( flags & KoTextFormat::Misspelled )
699 if ( flags & KoTextFormat::VAlign )
702 setRelativeTextSize( nf.relativeTextSize());
705 if ( flags & KoTextFormat::StrikeOut )
707 setStrikeOutStyle( nf.strikeOutStyle() );
708 setStrikeOutType (nf.strikeOutType());
710 if( flags & KoTextFormat::TextBackgroundColor)
711 setTextBackgroundColor(nf.textBackgroundColor());
712 if( flags & KoTextFormat::ExtendUnderLine)
714 setTextUnderlineColor(nf.textUnderlineColor());
715 setUnderlineType (nf.underlineType());
716 setUnderlineStyle (nf.underlineStyle());
718 if( flags & KoTextFormat::Language)
719 setLanguage(nf.language());
720 if( flags & KoTextFormat::ShadowText)
721 setShadow(nf.shadowDistanceX(), nf.shadowDistanceY(), nf.shadowColor());
722 if( flags & KoTextFormat::OffsetFromBaseLine)
723 setOffsetFromBaseLine(nf.offsetFromBaseLine());
724 if( flags & KoTextFormat::WordByWord)
725 setWordByWord(nf.wordByWord());
726 if( flags & KoTextFormat::Attribute)
727 setAttributeFont(nf.attributeFont());
728 if( flags & KoTextFormat::Hyphenation )
729 setHyphenation( nf.hyphenation());
730 if( flags & KoTextFormat::UnderLineWidth )
731 setUnderLineWidth( nf.underLineWidth());
738void KoTextFormat::setBold(
bool b )
740 if ( b == fn.bold() )
746void KoTextFormat::setMisspelled(
bool b )
748 if ( b == (
bool)missp )
754void KoTextFormat::setVAlign( VerticalAlignment a )
762void KoTextFormat::setItalic(
bool b )
764 if ( b == fn.italic() )
770void KoTextFormat::setUnderline(
bool b )
772 if ( b == fn.underline() )
774 fn.setUnderline( b );
778void KoTextFormat::setFamily(
const TQString &f )
780 if ( f == fn.family() )
786void KoTextFormat::setPointSize(
int s )
788 if ( s == fn.pointSize() )
790 fn.setPointSize( s );
794void KoTextFormat::setFont(
const TQFont &f )
799 fn.setStyleStrategy( TQFont::ForceOutline );
803void KoTextFormat::setColor(
const TQColor &c )
812int KoTextFormat::minLeftBearing()
const
814 if ( !painter || !painter->isActive() )
816 painter->setFont( fn );
817 return painter->fontMetrics().minLeftBearing();
820int KoTextFormat::minRightBearing()
const
822 if ( !painter || !painter->isActive() )
824 painter->setFont( fn );
825 return painter->fontMetrics().minRightBearing();
831void KoTextFormat::generateKey()
833 TQString k = fn.key();
836 k += TQString::number( (uint)col.rgb() );
838 k += TQString::number( (
int)isMisspelled() );
839 k += TQString::number( (
int)vAlign() );
842 if (m_textBackColor.isValid())
843 k += TQString::number( (uint)m_textBackColor.rgb() );
845 if ( m_textUnderlineColor.isValid())
846 k += TQString::number( (uint)m_textUnderlineColor.rgb() );
848 k += TQString::number( (
int)m_underlineType );
849 k += TQString::number( (
int)m_strikeOutType );
850 k += TQString::number( (
int)m_underlineStyle );
851 k += TQString::number( (
int)m_strikeOutStyle );
855 if ( d->m_shadowDistanceX != 0 || d->m_shadowDistanceY != 0 )
857 k += TQString::number( d->m_shadowDistanceX );
859 k += TQString::number( d->m_shadowDistanceY );
861 k += TQString::number( (uint)d->m_shadowColor.rgb() );
864 k += TQString::number( d->m_relativeTextSize);
866 k += TQString::number( d->m_offsetFromBaseLine);
868 k += TQString::number( (
int)d->m_bWordByWord);
869 k += TQString::number( (
int)m_attributeFont);
871 k += TQString::number( (
int)d->m_bHyphenation);
872 k += TQString::number( (
double)d->m_underLineWidth);
880TQString KoTextFormat::getKey(
const TQFont &fn,
const TQColor &col,
bool misspelled, VerticalAlignment a )
882 TQString k = fn.key();
885 k += TQString::number( (uint)col.rgb() );
887 k += TQString::number( (
int)misspelled );
888 k += TQString::number( (
int)a );
895 k += TQString::number( (
int)U_NONE );
896 k += TQString::number( (
int)S_NONE );
897 k += TQString::number( (
int)U_SOLID );
898 k += TQString::number( (
int)S_SOLID );
919TQString KoTextFormat::key()
const
921 if ( m_key.isEmpty() )
926void KoTextFormat::addRef()
929#ifdef DEBUG_COLLECTION
931 kdDebug(32500) <<
" add ref of '" << k <<
"' to " << ref <<
" (" <<
this <<
") (coll " << collection <<
")" << endl;
935void KoTextFormat::removeRef()
940#ifdef DEBUG_COLLECTION
941 kdDebug(32500) <<
" remove ref of '" << k <<
"' to " << ref <<
" (" <<
this <<
") (coll " << collection <<
")" << endl;
944 collection->remove(
this );
947void KoTextFormat::setStrikeOutType (StrikeOutType _type)
949 if ( m_strikeOutType == _type )
951 m_strikeOutType = _type;
955void KoTextFormat::setUnderlineType (UnderlineType _type)
957 if ( m_underlineType == _type )
959 m_underlineType = _type;
963void KoTextFormat::setUnderlineStyle (UnderlineStyle _type)
965 if ( m_underlineStyle == _type )
967 m_underlineStyle = _type;
971void KoTextFormat::setStrikeOutStyle( StrikeOutStyle _type )
973 if ( m_strikeOutStyle == _type )
975 m_strikeOutStyle = _type;
979void KoTextFormat::setTextBackgroundColor(
const TQColor &_col)
981 if(m_textBackColor==_col)
983 m_textBackColor=_col;
986void KoTextFormat::setTextUnderlineColor(
const TQColor &_col)
988 if ( m_textUnderlineColor == _col )
990 m_textUnderlineColor=_col;
994void KoTextFormat::setShadow(
double shadowDistanceX,
double shadowDistanceY,
const TQColor& shadowColor )
996 if ( d->m_shadowDistanceX == shadowDistanceX &&
997 d->m_shadowDistanceY == shadowDistanceY &&
998 d->m_shadowColor == shadowColor )
1000 d->m_shadowDistanceX = shadowDistanceX;
1001 d->m_shadowDistanceY = shadowDistanceY;
1002 d->m_shadowColor = shadowColor;
1006void KoTextFormat::setRelativeTextSize(
double _size )
1008 if ( d->m_relativeTextSize == _size)
1010 d->m_relativeTextSize = _size;
1014void KoTextFormat::setOffsetFromBaseLine(
int _offset )
1016 if ( d->m_offsetFromBaseLine == _offset)
1018 d->m_offsetFromBaseLine = _offset;
1022void KoTextFormat::setWordByWord(
bool _b )
1024 if ( d->m_bWordByWord == _b)
1026 d->m_bWordByWord = _b;
1031void KoTextFormat::setAttributeFont(KoTextFormat::AttributeStyle _att )
1033 if ( m_attributeFont == _att)
1035 m_attributeFont = _att;
1043 if ( fn.weight() != format.fn.weight() )
1044 flags |= KoTextFormat::Bold;
1045 if ( fn.italic() != format.fn.italic() )
1046 flags |= KoTextFormat::Italic;
1047 if ( textUnderlineColor()!=format.textUnderlineColor() ||
1048 underlineType()!= format.underlineType() ||
1049 underlineStyle() != format.underlineStyle())
1050 flags |= KoTextFormat::ExtendUnderLine;
1051 if ( fn.family() != format.fn.family() )
1052 flags |= KoTextFormat::Family;
1053 if ( pointSize() != format.pointSize() )
1054 flags |= KoTextFormat::Size;
1055 if ( color() != format.color() )
1056 flags |= KoTextFormat::Color;
1057 if ( vAlign() != format.vAlign() ||
1058 relativeTextSize() != format.relativeTextSize())
1059 flags |= KoTextFormat::VAlign;
1060 if ( strikeOutType() != format.strikeOutType()
1061 || underlineStyle() != format.underlineStyle())
1062 flags |= KoTextFormat::StrikeOut;
1063 if ( textBackgroundColor() != format.textBackgroundColor() )
1064 flags |= KoTextFormat::TextBackgroundColor;
1065 if ( language() != format.language() )
1066 flags |= KoTextFormat::Language;
1067 if ( d->m_shadowDistanceX != format.shadowDistanceX()
1068 || d->m_shadowDistanceY != format.shadowDistanceY()
1069 || d->m_shadowColor != format.shadowColor() )
1070 flags |= KoTextFormat::ShadowText;
1071 if ( offsetFromBaseLine() != format.offsetFromBaseLine() )
1072 flags |= KoTextFormat::OffsetFromBaseLine;
1073 if ( wordByWord() != format.wordByWord() )
1074 flags |= KoTextFormat::WordByWord;
1075 if ( attributeFont() != format.attributeFont() )
1076 flags |= KoTextFormat::Attribute;
1077 if( hyphenation() != format.hyphenation() )
1078 flags |= KoTextFormat::Hyphenation;
1079 if( underLineWidth() != format.underLineWidth() )
1080 flags |= KoTextFormat::UnderLineWidth;
1086 if ( painter->device()->devType() == TQInternal::Printer )
1088 return TQApplication::palette().color( TQPalette::Active, TQColorGroup::Text );
1095 if ( vAlign() != KoTextFormat::AlignNormal )
1096 pointSizeLU = (int)( pointSizeLU *relativeTextSize() );
1102 if ( vAlign() != KoTextFormat::AlignNormal )
1103 return (
float)pointSize() * relativeTextSize();
1111 if ( !d->m_refFont || pointSize != d->m_refFont->pointSizeFloat() )
1113 delete d->m_refFont;
1114 d->m_refFont =
new TQFont( font() );
1115 d->m_refFont->setPointSizeFloat( pointSize );
1116 delete d->m_refFontMetrics;
1117 d->m_refFontMetrics = 0;
1120 return *d->m_refFont;
1132 if ( !d->m_screenFont || kAbs( pointSize - d->m_screenFont->pointSizeFloat() ) > 1E-4 )
1134 delete d->m_screenFont;
1135 d->m_screenFont =
new TQFont( font() );
1136 d->m_screenFont->setPointSizeFloat( pointSize );
1137 delete d->m_screenFontMetrics;
1138 d->m_screenFontMetrics = 0;
1141 return *d->m_screenFont;
1148 if ( !d->m_screenFontMetrics )
1151 d->m_screenFontMetrics =
new TQFontMetrics( f );
1154 return *d->m_screenFontMetrics;
1161 if ( !d->m_refFontMetrics )
1164 d->m_refFontMetrics =
new TQFontMetrics( f );
1167 return *d->m_refFontMetrics;
1170TQFont KoTextFormat::smallCapsFont(
const KoTextZoomHandler* zh,
bool applyZoom )
const
1174 double pointSize = font.pointSize() * ((double)fm.boundingRect(
"x").height()/(double)fm.boundingRect(
"X").height());
1175 font.setPointSizeFloat( pointSize );
1180 const KoTextParag* parag,
int i )
const
1182 ushort unicode = c->c.unicode();
1183 if ( !c->charStop || unicode == 0xad || unicode == 0x2028 )
1185 Q_ASSERT( !c->isCustom() );
1186 if( c->isCustom() ) {
1187 if( c->customItem()->placement() == KoTextCustomItem::PlaceInline ) {
1189 double w = KoTextZoomHandler::layoutUnitPtToPt( c->customItem()->width );
1190 return tqRound( applyZoom ? ( w * zh->
zoomFactorX() ) : w );
1197 if( r < 0x06 || (r > 0x1f && !(r > 0xd7 && r < 0xe0)) )
1200 if ( attributeFont() == KoTextFormat::ATT_SMALL_CAPS && c->c.upper() != c->c )
1202 pixelww = TQFontMetrics( smallCapsFont( zh, applyZoom ) ).width( displayedChar( c->c ) );
1212 Q_ASSERT( unicode < 256 );
1213 pixelww = d->m_screenWidths[ unicode ];
1215 if ( pixelww == 0 ) {
1217 Q_ASSERT( pixelww < 65535 );
1218 d->m_screenWidths[ unicode ] = pixelww;
1228 bool smallCaps = ( attributeFont() == KoTextFormat::ATT_SMALL_CAPS && c->c.upper() != c->c );
1235 int end = TQMIN( parag->length(), i + 8 );
1236 while ( pos < end ) {
1237 str += displayedChar( parag->at(pos)->c );
1240 pixelww = fontMetrics.charWidth( str, off );
1244 kdDebug(32500) <<
"KoTextFormat::charWidth: char=" << TQString(c->c) <<
" format=" << key()
1245 <<
", applyZoom=" << applyZoom <<
" pixel-width=" << pixelww << endl;
1250int KoTextFormat::height()
const
1252 if ( d->m_refHeight < 0 )
1256 if ( vAlign() == KoTextFormat::AlignSuperScript )
1258 else if ( vAlign() == KoTextFormat::AlignSubScript )
1262 if ( d->m_shadowDistanceY != 0 ) {
1264 h += (int)(POINT_TO_INCH(
static_cast<double>( KoGlobal::dpiY() ) ) * TQABS( d->m_shadowDistanceY ) );
1271 return d->m_refHeight;
1274int KoTextFormat::offsetX() const
1281 if ( d->m_shadowDistanceX < 0 )
1284 off += (int)(POINT_TO_INCH(
static_cast<double>( KoGlobal::dpiX() ) ) * lupt );
1290int KoTextFormat::offsetY() const
1295 if ( d->m_shadowDistanceY < 0 )
1298 off += (int)(POINT_TO_INCH(
static_cast<double>( KoGlobal::dpiY() ) ) * lupt );
1304TQString KoTextFormat::displayedString(
const TQString& str )
const
1306 switch ( m_attributeFont ) {
1310 case ATT_SMALL_CAPS:
1315 kdDebug(32500)<<
" Error in AttributeStyle \n";
1320TQChar KoTextFormat::displayedChar( TQChar c )
const
1322 if ( c.unicode() == 0xa0 )
1324 switch ( m_attributeFont ) {
1327 case ATT_SMALL_CAPS:
1333 kdDebug(32500)<<
" Error in AttributeStyle \n";
1338int KoTextFormat::ascent()
const
1340 if ( d->m_refAscent < 0 )
1344 if ( offsetFromBaseLine()>0 )
1345 h += offsetFromBaseLine();
1346 if ( vAlign() == KoTextFormat::AlignSuperScript )
1352 return d->m_refAscent;
1355int KoTextFormat::descent()
const
1357 if ( d->m_refDescent < 0 )
1361 if ( offsetFromBaseLine()<0 )
1362 h -= offsetFromBaseLine();
1367 return d->m_refDescent;
1383void KoTextFormat::applyCharStyle(
KoCharStyle *_style )
1385 d->m_charStyle = _style;
1390 return d->m_charStyle;
1398 if ( shadowDistanceX != 0 || shadowDistanceY != 0 )
1400 TQString css = shadowColor.name() +
" ";
1401 css += TQString::number(shadowDistanceX) +
"pt ";
1402 css += TQString::number(shadowDistanceY) +
"pt";
1410 return shadowAsCss( d->m_shadowDistanceX, d->m_shadowDistanceY, d->m_shadowColor );
1415 TQString css = _css.simplifyWhiteSpace();
1416 if ( css.isEmpty() || css ==
"none" )
1418 d->m_shadowDistanceX = 0;
1419 d->m_shadowDistanceY = 0;
1420 d->m_shadowColor = TQColor();
1423 TQStringList tokens = TQStringList::split(
' ', css);
1424 if ( tokens.isEmpty() ) {
1425 kdWarning(32500) <<
"Parse error in text-shadow: " << css << endl;
1429 TQColor col( tokens.first() );
1430 if ( col.isValid() )
1432 else if ( tokens.count() > 1 )
1434 col.setNamedColor( tokens.last() );
1435 if ( col.isValid() )
1438 d->m_shadowColor = col;
1440 if ( !tokens.isEmpty() ) {
1445 if ( !tokens.isEmpty() ) {
1455TQColor KoTextFormat::shadowColor()
const
1457 if ( d->m_shadowColor.isValid() )
1458 return d->m_shadowColor;
1465 return zh->zoomItX( d->m_shadowDistanceX );
1470 return zh->zoomItY( d->m_shadowDistanceY );
1474TQString KoTextFormat::underlineStyleToString( KoTextFormat::UnderlineStyle _lineType )
1476 TQString strLineType;
1477 switch ( _lineType )
1479 case KoTextFormat::U_SOLID:
1480 strLineType =
"solid";
1482 case KoTextFormat::U_DASH:
1483 strLineType =
"dash";
1485 case KoTextFormat::U_DOT:
1488 case KoTextFormat::U_DASH_DOT:
1489 strLineType=
"dashdot";
1491 case KoTextFormat::U_DASH_DOT_DOT:
1492 strLineType=
"dashdotdot";
1498TQString KoTextFormat::strikeOutStyleToString( KoTextFormat::StrikeOutStyle _lineType )
1500 TQString strLineType;
1501 switch ( _lineType )
1503 case KoTextFormat::S_SOLID:
1504 strLineType =
"solid";
1506 case KoTextFormat::S_DASH:
1507 strLineType =
"dash";
1509 case KoTextFormat::S_DOT:
1512 case KoTextFormat::S_DASH_DOT:
1513 strLineType=
"dashdot";
1515 case KoTextFormat::S_DASH_DOT_DOT:
1516 strLineType=
"dashdotdot";
1522KoTextFormat::UnderlineStyle KoTextFormat::stringToUnderlineStyle(
const TQString & _str )
1524 if ( _str ==
"solid")
1525 return KoTextFormat::U_SOLID;
1526 else if ( _str ==
"dash" )
1527 return KoTextFormat::U_DASH;
1528 else if ( _str ==
"dot" )
1529 return KoTextFormat::U_DOT;
1530 else if ( _str ==
"dashdot")
1531 return KoTextFormat::U_DASH_DOT;
1532 else if ( _str==
"dashdotdot")
1533 return KoTextFormat::U_DASH_DOT_DOT;
1535 return KoTextFormat::U_SOLID;
1538KoTextFormat::StrikeOutStyle KoTextFormat::stringToStrikeOutStyle(
const TQString & _str )
1540 if ( _str ==
"solid")
1541 return KoTextFormat::S_SOLID;
1542 else if ( _str ==
"dash" )
1543 return KoTextFormat::S_DASH;
1544 else if ( _str ==
"dot" )
1545 return KoTextFormat::S_DOT;
1546 else if ( _str ==
"dashdot")
1547 return KoTextFormat::S_DASH_DOT;
1548 else if ( _str==
"dashdotdot")
1549 return KoTextFormat::S_DASH_DOT_DOT;
1551 return KoTextFormat::S_SOLID;
1554TQString KoTextFormat::attributeFontToString( KoTextFormat::AttributeStyle _attr )
1556 if (_attr == KoTextFormat::ATT_NONE )
1557 return TQString(
"none");
1558 else if ( _attr == KoTextFormat::ATT_UPPER )
1559 return TQString(
"uppercase");
1560 else if ( _attr == KoTextFormat::ATT_LOWER )
1561 return TQString(
"lowercase");
1562 else if ( _attr == KoTextFormat::ATT_SMALL_CAPS )
1563 return TQString(
"smallcaps");
1565 return TQString(
"none");
1568KoTextFormat::AttributeStyle KoTextFormat::stringToAttributeFont(
const TQString & _str )
1570 if ( _str ==
"none" )
1571 return KoTextFormat::ATT_NONE;
1572 else if ( _str ==
"uppercase")
1573 return KoTextFormat::ATT_UPPER;
1574 else if ( _str ==
"lowercase")
1575 return KoTextFormat::ATT_LOWER;
1576 else if ( _str ==
"smallcaps" )
1577 return KoTextFormat::ATT_SMALL_CAPS;
1579 return KoTextFormat::ATT_NONE;
1583void KoTextFormat::setHyphenation(
bool b )
1585 if ( d->m_bHyphenation == b )
1587 d->m_bHyphenation = b;
1592void KoTextFormat::setUnderLineWidth(
double ulw )
1594 if ( d->m_underLineWidth == ulw )
1596 d->m_underLineWidth = ulw;
1601void KoTextFormat::setLanguage(
const TQString & _lang)
1603 if ( m_language == _lang )
1609TQStringList KoTextFormat::underlineTypeList()
1612 lst <<i18n(
"Underline Style",
"None");
1613 lst <<i18n(
"Single");
1614 lst <<i18n(
"Double");
1615 lst <<i18n(
"Simple Bold");
1620TQStringList KoTextFormat::strikeOutTypeList()
1623 lst <<i18n(
"Strikeout Style",
"None");
1624 lst <<i18n(
"Single");
1625 lst <<i18n(
"Double");
1626 lst <<i18n(
"Simple Bold");
1630TQStringList KoTextFormat::fontAttributeList()
1633 lst <<i18n(
"Normal");
1634 lst <<i18n(
"Uppercase");
1635 lst <<i18n(
"Lowercase");
1636 lst <<i18n(
"Small Caps");
1640TQStringList KoTextFormat::underlineStyleList()
1645 lst <<
"_ _ _ _ _ _";
1646 lst <<
"___ _ ___ _";
1647 lst <<
"___ _ _ ___";
1651TQStringList KoTextFormat::strikeOutStyleList()
1656 lst <<
"_ _ _ _ _ _";
1657 lst <<
"___ _ ___ _";
1658 lst <<
"___ _ _ ___";
1663void KoTextFormat::printDebug()
1665 TQString col = color().isValid() ? color().name() : TQString(
"(default)");
1666 kdDebug(32500) <<
"format '" << key() <<
"' (" << (
void*)
this <<
"):"
1667 <<
" refcount: " << ref
1668 <<
" realfont: " << TQFontInfo( font() ).family()
1669 <<
" color: " << col <<
" shadow=" <<
shadowAsCss() << endl;
1675KoTextFormatCollection::KoTextFormatCollection()
1678#ifdef DEBUG_COLLECTION
1679 kdDebug(32500) <<
"KoTextFormatCollection::KoTextFormatCollection " <<
this << endl;
1681 defFormat =
new KoTextFormat( TQApplication::font(), TQColor(), TDEGlobal::locale()->language(),
false );
1682 lastFormat = cres = 0;
1684 cKey.setAutoDelete(
true );
1688KoTextFormatCollection::KoTextFormatCollection(
const TQFont& defaultFont,
const TQColor& defaultColor,
const TQString & defaultLanguage,
bool defaultHyphenation )
1691#ifdef DEBUG_COLLECTION
1692 kdDebug(32500) <<
"KoTextFormatCollection::KoTextFormatCollection " <<
this << endl;
1694 defFormat =
new KoTextFormat( defaultFont, defaultColor, defaultLanguage, defaultHyphenation );
1695 lastFormat = cres = 0;
1697 cKey.setAutoDelete(
true );
1701KoTextFormatCollection::~KoTextFormatCollection()
1703#ifdef DEBUG_COLLECTION
1704 kdDebug(32500) <<
"KoTextFormatCollection::~KoTextFormatCollection " <<
this << endl;
1712 if ( f->parent() ==
this || f == defFormat ) {
1713#ifdef DEBUG_COLLECTION
1714 kdDebug(32500) <<
" format(f) need '" << f->key() <<
"', best case!" << endl;
1717 lastFormat->addRef();
1721 if ( f == lastFormat || ( lastFormat && f->key() == lastFormat->key() ) ) {
1722#ifdef DEBUG_COLLECTION
1723 kdDebug(32500) <<
" format(f) need '" << f->key() <<
"', good case!" << endl;
1725 lastFormat->addRef();
1733 if ( f->isAnchor() ) {
1734 lastFormat = createFormat( *f );
1735 lastFormat->collection = 0;
1742#ifdef DEBUG_COLLECTION
1743 kdDebug(32500) <<
" format(f) need '" << f->key() <<
"', normal case!" << endl;
1746 lastFormat->addRef();
1750 if ( f->key() == defFormat->key() )
1753#ifdef DEBUG_COLLECTION
1754 kdDebug(32500) <<
" format(f) need '" << f->key() <<
"', worst case!" << endl;
1756 lastFormat = createFormat( *f );
1757 lastFormat->collection =
this;
1758 cKey.insert( lastFormat->key(), lastFormat );
1759 Q_ASSERT( f->key() == lastFormat->key() );
1765 if ( cres && kof == of->key() && knf == nf->key() && cflags == flags ) {
1766#ifdef DEBUG_COLLECTION
1767 kdDebug(32500) <<
" format(of,nf,flags) mix of '" << of->key() <<
"' and '" << nf->key() <<
"', best case!" << endl;
1773#ifdef DEBUG_COLLECTION
1774 kdDebug(32500) <<
" format(of,nf," << flags <<
") calling createFormat(of=" << of <<
" " << of->key() <<
")" << endl;
1776 cres = createFormat( *of );
1781#ifdef DEBUG_COLLECTION
1782 kdDebug(32500) <<
" format(of,nf," << flags <<
") calling copyFormat(nf=" << nf <<
" " << nf->key() <<
")" << endl;
1784 cres->copyFormat( *nf, flags );
1788#ifdef DEBUG_COLLECTION
1789 kdDebug(32500) <<
" format(of,nf,flags) mix of '" << of->key() <<
"' and '" << nf->key() <<
", worst case!" << endl;
1791 cres->collection =
this;
1792 cKey.insert( cres->key(), cres );
1794#ifdef DEBUG_COLLECTION
1795 kdDebug(32500) <<
" format(of,nf,flags) mix of '" << of->key() <<
"' and '" << nf->key() <<
", good case!" << endl;
1806KoTextFormat *KoTextFormatCollection::format(
const TQFont &f,
const TQColor &c,
const TQString & language,
bool hyphen )
1808 if ( cachedFormat && cfont == f && ccol == c ) {
1809#ifdef DEBUG_COLLECTION
1810 kdDebug(32500) <<
" format of font and col '" << cachedFormat->key() <<
"' - best case" << endl;
1812 cachedFormat->addRef();
1813 return cachedFormat;
1816 TQString key = KoTextFormat::getKey( f, c,
false, KoTextFormat::AlignNormal );
1817 cachedFormat = cKey.find( key );
1821 if ( cachedFormat ) {
1822#ifdef DEBUG_COLLECTION
1823 kdDebug(32500) <<
" format of font and col '" << cachedFormat->key() <<
"' - good case" << endl;
1825 cachedFormat->addRef();
1826 return cachedFormat;
1829 if ( key == defFormat->key() )
1832 cachedFormat = createFormat( f, c, language, hyphen );
1833 cachedFormat->collection =
this;
1834 cKey.insert( cachedFormat->key(), cachedFormat );
1835 if ( cachedFormat->key() != key )
1836 kdWarning() <<
"ASSERT: keys for format not identical: '" << cachedFormat->key() <<
" '" << key <<
"'" << endl;
1837#ifdef DEBUG_COLLECTION
1838 kdDebug(32500) <<
" format of font and col '" << cachedFormat->key() <<
"' - worst case" << endl;
1840 return cachedFormat;
1846 if ( lastFormat == f )
1850 if ( cachedFormat == f )
1852 cKey.remove( f->key() );
1855void KoTextFormatCollection::zoomChanged()
1857 TQDictIterator<KoTextFormat> it( cKey );
1858 for ( ; it.current(); ++it ) {
1859 it.current()->zoomChanged();
1864void KoTextFormatCollection::setPainter( TQPainter *p )
1866 TQDictIterator<KoTextFormat> it( cKey );
1868 while ( ( f = it.current() ) ) {
1876void KoTextFormatCollection::debug()
1878 kdDebug(32500) <<
"------------ KoTextFormatCollection: debug --------------- BEGIN" << endl;
1879 kdDebug(32500) <<
"Default Format: '" << defFormat->key() <<
"' (" << (
void*)defFormat <<
"): realfont: " << TQFontInfo( defFormat->font() ).family() << endl;
1880 TQDictIterator<KoTextFormat> it( cKey );
1881 for ( ; it.current(); ++it ) {
1882 Q_ASSERT(it.currentKey() == it.current()->key());
1883 if(it.currentKey() != it.current()->key())
1884 kdDebug(32500) <<
"**** MISMATCH key=" << it.currentKey() <<
" (see line below for format)" << endl;
1885 it.current()->printDebug();
1887 kdDebug(32500) <<
"------------ KoTextFormatCollection: debug --------------- END" << endl;
A KoCharStyle is a set of formatting attributes (font, color, etc.) to be applied to a run of text.
PropertyType
The types of properties.
@ TextType
TextType is always text-properties.
void addProperty(const TQString &propName, const TQString &propValue, PropertyType type=DefaultType)
Add a property to the style.
void addPropertyPt(const TQString &propName, double propValue, PropertyType type=DefaultType)
Add a property which represents a distance, measured in pt The number is written out with the highest...
Used during loading of Oasis format (and discarded at the end of the loading).
TQString generator() const
Return the <meta:generator> of the document, e.g. "KOffice/1.4.0a".
Used during saving to Oasis format (and discarded at the end of the saving).
This class implements a stack for the different styles of an object.
bool hasAttributeNS(const char *nsURI, const char *localName, const char *detail=0) const
Check if any of the styles on the stack has an attribute called 'name'-'detail' where detail is e....
void setTypeProperties(const char *typeProperties)
Set the type of properties that will be looked for.
double fontSize() const
Special case for the current font size, due to special handling of fo:font-size="115%".
TQString attributeNS(const char *nsURI, const char *localName, const char *detail=0) const
Search for the attribute called 'name', starting on top of the stack, and return it.
Each character (KoTextStringChar) points to a KoTextFormat that defines the formatting of that charac...
void save(KoGenStyle &gs, KoSavingContext &context, KoTextFormat *refFormat=0) const
Save a text format to OASIS XML Only saves what differs from @refFormat, if set.
const TQFontMetrics & screenFontMetrics(const KoTextZoomHandler *zh) const
Returns the font metrics for the font used at the zoom & resolution given by 'zh'.
void parseShadowFromCss(const TQString &css)
Load shadow attributes from a css string, used when loading.
int shadowY(KoTextZoomHandler *zh) const
Return the amount of pixels for the vertical shadow distance at a given zoom level.
int charWidth(const KoTextZoomHandler *zh, bool applyZoom, const KoTextStringChar *c, const KoTextParag *parag, int i) const
Return the width of one char in one paragraph.
void load(KoOasisContext &context)
Load a text format from OASIS XML.
const TQFontMetrics & refFontMetrics() const
int width(const TQChar &c) const
Return the width of one char (from a string, not necessarily from a paragraph) in LU pixels.
float screenPointSize(const KoTextZoomHandler *zh) const
TQString shadowAsCss() const
Return css string for the shadow, used when saving.
int shadowX(KoTextZoomHandler *zh) const
Return the amount of pixels for the horizontal shadow distance at a given zoom level.
void zoomChanged()
Called when the zoom or resolution changes.
TQFont screenFont(const KoTextZoomHandler *zh) const
Returns the font to be used at the zoom & resolution given by 'zh'.
static TQColor defaultTextColor(TQPainter *painter)
Call this when a text color is set to 'invalid', meaning 'whatever the default for the color scheme i...
int charWidthLU(const KoTextStringChar *c, const KoTextParag *parag, int i) const
Return the width of one char in LU pixels.
int compare(const KoTextFormat &format) const
Return a set of flags showing the differences between this and 'format'.
float refPointSize() const
This class extends KoZoomHandler to add support for WYSIWYG text layouting.
double layoutUnitToFontSize(int luSize, bool) const
Given the font size for the font in layout units, in pt (use pointSize()) this returns the font size ...
static double ptToLayoutUnitPt(double pt)
Not zoom dependent.
static double parseValue(TQString value, double defaultVal=0.0)
parse common KOffice and OO values, like "10cm", "5mm" to pt
double zoomFactorX() const
Zoom factor for X.
TDEAction * find(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)