diff --git a/jni/NativeFormats/fbreader/src/bookmodel/BookReader.cpp b/jni/NativeFormats/fbreader/src/bookmodel/BookReader.cpp index 38a5267e0..5c61e8339 100644 --- a/jni/NativeFormats/fbreader/src/bookmodel/BookReader.cpp +++ b/jni/NativeFormats/fbreader/src/bookmodel/BookReader.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "BookReader.h" #include "BookModel.h" diff --git a/jni/NativeFormats/fbreader/src/bookmodel/BookReader.h b/jni/NativeFormats/fbreader/src/bookmodel/BookReader.h index 3089639ae..d5a053c1d 100644 --- a/jni/NativeFormats/fbreader/src/bookmodel/BookReader.h +++ b/jni/NativeFormats/fbreader/src/bookmodel/BookReader.h @@ -33,6 +33,7 @@ class BookModel; class ZLTextModel; class ZLInputStream; class ZLCachedMemoryAllocator; +class ZLTextStyleEntry; class BookReader { diff --git a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.cpp b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.cpp index 6ca4d0651..b43f746dd 100644 --- a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.cpp +++ b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.cpp @@ -160,28 +160,26 @@ shared_ptr StyleSheetTable::createControl(const AttributeMap & num = 700; } else if (bold[0] == "normal") { num = 400; - } else if ((bold[0].length() == 3) && - (bold[0][1] == '0') && - (bold[0][2] == '0') && - (bold[0][0] >= '1') && - (bold[0][0] <= '9')) { - num = 100 * (bold[0][0] - '0'); } else if (bold[0] == "bolder") { + // TODO: implement } else if (bold[0] == "lighter") { + // TODO: implement + } else { + num = ZLStringUtil::stringToInteger(bold[0], -1); } if (num != -1) { - entry->setFontModifier(FONT_MODIFIER_BOLD, num >= 600); + entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_BOLD, num >= 600); } } const std::vector &italic = values(styles, "font-style"); if (!italic.empty()) { - entry->setFontModifier(FONT_MODIFIER_ITALIC, italic[0] == "italic"); + entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_ITALIC, italic[0] == "italic"); } const std::vector &variant = values(styles, "font-variant"); if (!variant.empty()) { - entry->setFontModifier(FONT_MODIFIER_SMALLCAPS, variant[0] == "small-caps"); + entry->setFontModifier(ZLTextStyleEntry::FONT_MODIFIER_SMALLCAPS, variant[0] == "small-caps"); } const std::vector &fontFamily = values(styles, "font-family"); diff --git a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.h b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.h index 1dd2caadf..7121e877a 100644 --- a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.h +++ b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.h @@ -27,6 +27,7 @@ #include #include +#include class StyleSheetTable { diff --git a/jni/NativeFormats/fbreader/src/formats/rtf/RtfBookReader.cpp b/jni/NativeFormats/fbreader/src/formats/rtf/RtfBookReader.cpp index 183305d98..e7ac714e6 100644 --- a/jni/NativeFormats/fbreader/src/formats/rtf/RtfBookReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/rtf/RtfBookReader.cpp @@ -21,6 +21,7 @@ #include #include +#include #include "RtfBookReader.h" #include "../../bookmodel/BookModel.h" diff --git a/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp b/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp index 30343096f..25daae619 100644 --- a/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp +++ b/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp @@ -105,11 +105,28 @@ std::string ZLStringUtil::doubleToString(double value) { return buf; } -double ZLStringUtil::stringToDouble(const std::string &value, double defaultValue) { - if (!value.empty()) { +double ZLStringUtil::stringToDouble(const std::string &str, double defaultValue) { + if (!str.empty()) { setlocale(LC_NUMERIC, "C"); - return atof(value.c_str()); + return atof(str.c_str()); } else { return defaultValue; } } + +int ZLStringUtil::stringToInteger(const std::string &str, int defaultValue) { + if (str.empty()) { + return defaultValue; + } + if (!isdigit(str[0]) && (str.length() == 1 || str[0] != '-' || !isdigit(str[1]))) { + return defaultValue; + } + + for (size_t i = 1; i < str.length(); ++i) { + if (!isdigit(str[i])) { + return defaultValue; + } + } + + return atoi(str.c_str()); +} diff --git a/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.h b/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.h index 5abf1ee4b..3a3b5823b 100644 --- a/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.h +++ b/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.h @@ -31,6 +31,7 @@ private: public: static bool stringStartsWith(const std::string &str, const std::string &start); static bool stringEndsWith(const std::string &str, const std::string &end); + static void appendNumber(std::string &str, unsigned int n); static void append(std::string &str, const std::vector &buffer); static void stripWhiteSpaces(std::string &str); @@ -39,6 +40,7 @@ public: static std::string doubleToString(double value); static double stringToDouble(const std::string &value, double defaultValue); + static int stringToInteger(const std::string &str, int defaultValue); }; #endif /* __ZLSTRINGUTIL_H__ */ diff --git a/jni/NativeFormats/zlibrary/text/src/model/ZLTextFontModifier.h b/jni/NativeFormats/zlibrary/text/src/model/ZLTextFontModifier.h deleted file mode 100644 index 73847a5fc..000000000 --- a/jni/NativeFormats/zlibrary/text/src/model/ZLTextFontModifier.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifndef __ZLTEXTFONTMODIFIER_H__ -#define __ZLTEXTFONTMODIFIER_H__ - -enum ZLTextFontModifier { - FONT_MODIFIER_DEFAULT = 0, - FONT_MODIFIER_BOLD = 1 << 0, - FONT_MODIFIER_ITALIC = 1 << 1, - FONT_MODIFIER_SMALLCAPS = 1 << 2, -}; - -#endif /* __ZLTEXTFONTMODIFIER_H__ */ diff --git a/jni/NativeFormats/zlibrary/text/src/model/ZLTextModel.h b/jni/NativeFormats/zlibrary/text/src/model/ZLTextModel.h index b999ff877..cc8533dec 100644 --- a/jni/NativeFormats/zlibrary/text/src/model/ZLTextModel.h +++ b/jni/NativeFormats/zlibrary/text/src/model/ZLTextModel.h @@ -32,8 +32,7 @@ //#include #include -class ZLTextParagraph; -class ZLTextTreeParagraph; +class ZLTextStyleEntry; class ZLTextModel { diff --git a/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.cpp b/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.cpp index 7f0ed136f..e7251df67 100644 --- a/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.cpp +++ b/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.cpp @@ -26,6 +26,7 @@ #include "ZLCachedMemoryAllocator.h" #include "ZLTextParagraph.h" +#include "ZLTextStyleEntry.h" const shared_ptr ResetBidiEntry::Instance = new ResetBidiEntry(); diff --git a/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.h b/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.h index 56d5ba180..9cbac60a7 100644 --- a/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.h +++ b/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.h @@ -29,7 +29,6 @@ #include #include #include -#include class ZLImage; typedef std::map > ZLImageMap; @@ -58,85 +57,6 @@ private: // disable copying const ZLTextParagraphEntry &operator = (const ZLTextParagraphEntry &entry); }; -class ZLTextStyleEntry : public ZLTextParagraphEntry { - -public: - enum SizeUnit { - SIZE_UNIT_PIXEL, - SIZE_UNIT_EM_100, - SIZE_UNIT_EX_100, - SIZE_UNIT_PERCENT - }; - - struct Metrics { - Metrics(int fontSize, int fontXHeight, int fullWidth, int fullHeight); - - int FontSize; - int FontXHeight; - int FullWidth; - int FullHeight; - }; - - enum Length { - LENGTH_LEFT_INDENT = 0, - LENGTH_RIGHT_INDENT = 1, - LENGTH_FIRST_LINE_INDENT_DELTA = 2, - LENGTH_SPACE_BEFORE = 3, - LENGTH_SPACE_AFTER = 4, - NUMBER_OF_LENGTHS = 5, - }; - -private: - struct LengthType { - SizeUnit Unit; - short Size; - }; - -public: - ZLTextStyleEntry(); - ZLTextStyleEntry(char *address); - ~ZLTextStyleEntry(); - - bool isEmpty() const; - - bool isLengthSupported(Length name) const; - short length(Length name, const Metrics &metrics) const; - void setLength(Length name, short length, SizeUnit unit); - - bool isAlignmentTypeSupported() const; - ZLTextAlignmentType alignmentType() const; - void setAlignmentType(ZLTextAlignmentType alignmentType); - - unsigned char supportedFontModifier() const; - unsigned char fontModifier() const; - void setFontModifier(ZLTextFontModifier style, bool set); - - bool isFontSizeMagSupported() const; - signed char fontSizeMag() const; - void setFontSizeMag(signed char fontSizeMag); - - bool isFontFamilySupported() const; - const std::string &fontFamily() const; - void setFontFamily(const std::string &fontFamily); - - static const unsigned int SUPPORTS_ALIGNMENT_TYPE = 1U << NUMBER_OF_LENGTHS; - static const unsigned int SUPPORTS_FONT_SIZE_MAG = 1U << (NUMBER_OF_LENGTHS + 1); - static const unsigned int SUPPORTS_FONT_FAMILY = 1U << (NUMBER_OF_LENGTHS + 2); - -private: - unsigned int myMask; - - LengthType myLengths[NUMBER_OF_LENGTHS]; - - ZLTextAlignmentType myAlignmentType; - unsigned char mySupportedFontModifier; - unsigned char myFontModifier; - signed char myFontSizeMag; - std::string myFontFamily; - -friend class ZLTextModel; -}; - class ZLTextControlEntry : public ZLTextParagraphEntry { protected: @@ -330,43 +250,6 @@ private: inline ZLTextParagraphEntry::ZLTextParagraphEntry() {} inline ZLTextParagraphEntry::~ZLTextParagraphEntry() {} -inline ZLTextStyleEntry::ZLTextStyleEntry() : myMask(0), myAlignmentType(ALIGN_UNDEFINED), mySupportedFontModifier(0), myFontModifier(0), myFontSizeMag(0) {} -inline ZLTextStyleEntry::~ZLTextStyleEntry() {} - -inline ZLTextStyleEntry::Metrics::Metrics(int fontSize, int fontXHeight, int fullWidth, int fullHeight) : FontSize(fontSize), FontXHeight(fontXHeight), FullWidth(fullWidth), FullHeight(fullHeight) {} - -inline bool ZLTextStyleEntry::isEmpty() const { return myMask == 0; } - -inline bool ZLTextStyleEntry::isLengthSupported(Length name) const { return (myMask & (1U << name)) != 0; } -inline void ZLTextStyleEntry::setLength(Length name, short length, SizeUnit unit) { - myLengths[name].Size = length; - myLengths[name].Unit = unit; - myMask |= 1U << name; -} - -inline bool ZLTextStyleEntry::isAlignmentTypeSupported() const { return (myMask & SUPPORTS_ALIGNMENT_TYPE) == SUPPORTS_ALIGNMENT_TYPE; } -inline ZLTextAlignmentType ZLTextStyleEntry::alignmentType() const { return myAlignmentType; } -inline void ZLTextStyleEntry::setAlignmentType(ZLTextAlignmentType alignmentType) { myAlignmentType = alignmentType; myMask |= SUPPORTS_ALIGNMENT_TYPE; } - -inline unsigned char ZLTextStyleEntry::supportedFontModifier() const { return mySupportedFontModifier; } -inline unsigned char ZLTextStyleEntry::fontModifier() const { return myFontModifier; } -inline void ZLTextStyleEntry::setFontModifier(ZLTextFontModifier style, bool set) { - if (set) { - myFontModifier |= style; - } else { - myFontModifier &= ~style; - } - mySupportedFontModifier |= style; -} - -inline bool ZLTextStyleEntry::isFontSizeMagSupported() const { return (myMask & SUPPORTS_FONT_SIZE_MAG) == SUPPORTS_FONT_SIZE_MAG; } -inline signed char ZLTextStyleEntry::fontSizeMag() const { return myFontSizeMag; } -inline void ZLTextStyleEntry::setFontSizeMag(signed char fontSizeMag) { myFontSizeMag = fontSizeMag; myMask |= SUPPORTS_FONT_SIZE_MAG; } - -inline bool ZLTextStyleEntry::isFontFamilySupported() const { return (myMask & SUPPORTS_FONT_FAMILY) == SUPPORTS_FONT_FAMILY; } -inline const std::string &ZLTextStyleEntry::fontFamily() const { return myFontFamily; } -inline void ZLTextStyleEntry::setFontFamily(const std::string &fontFamily) { myFontFamily = fontFamily; myMask |= SUPPORTS_FONT_FAMILY; } - inline ZLTextControlEntry::ZLTextControlEntry(ZLTextKind kind, bool isStart) : myKind(kind), myStart(isStart) {} inline ZLTextControlEntry::~ZLTextControlEntry() {} inline ZLTextKind ZLTextControlEntry::kind() const { return myKind; } diff --git a/jni/NativeFormats/zlibrary/text/src/model/ZLTextStyleEntry.h b/jni/NativeFormats/zlibrary/text/src/model/ZLTextStyleEntry.h new file mode 100644 index 000000000..7bedca796 --- /dev/null +++ b/jni/NativeFormats/zlibrary/text/src/model/ZLTextStyleEntry.h @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2004-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __ZLTEXTSTYLEENTRY_H__ +#define __ZLTEXTSTYLEENTRY_H__ + +#include + +#include +#include + +class ZLTextStyleEntry : public ZLTextParagraphEntry { + +public: + enum SizeUnit { + SIZE_UNIT_PIXEL, + SIZE_UNIT_EM_100, + SIZE_UNIT_EX_100, + SIZE_UNIT_PERCENT + }; + + struct Metrics { + Metrics(int fontSize, int fontXHeight, int fullWidth, int fullHeight); + + int FontSize; + int FontXHeight; + int FullWidth; + int FullHeight; + }; + + enum FontModifier { + FONT_MODIFIER_DEFAULT = 0, + FONT_MODIFIER_BOLD = 1 << 0, + FONT_MODIFIER_ITALIC = 1 << 1, + FONT_MODIFIER_UNDERLINED = 1 << 2, + FONT_MODIFIER_STRIKEDTHROUGH = 1 << 3, + FONT_MODIFIER_SMALLCAPS = 1 << 4, + }; + + enum Length { + LENGTH_LEFT_INDENT = 0, + LENGTH_RIGHT_INDENT = 1, + LENGTH_FIRST_LINE_INDENT_DELTA = 2, + LENGTH_SPACE_BEFORE = 3, + LENGTH_SPACE_AFTER = 4, + NUMBER_OF_LENGTHS = 5, + }; + + static const unsigned int SUPPORTS_ALIGNMENT_TYPE = 1U << NUMBER_OF_LENGTHS; + static const unsigned int SUPPORTS_FONT_SIZE_MAG = 1U << (NUMBER_OF_LENGTHS + 1); + static const unsigned int SUPPORTS_FONT_FAMILY = 1U << (NUMBER_OF_LENGTHS + 2); + +private: + struct LengthType { + SizeUnit Unit; + short Size; + }; + +public: + ZLTextStyleEntry(); + ZLTextStyleEntry(char *address); + ~ZLTextStyleEntry(); + + bool isEmpty() const; + + bool isLengthSupported(Length name) const; + short length(Length name, const Metrics &metrics) const; + void setLength(Length name, short length, SizeUnit unit); + + bool isAlignmentTypeSupported() const; + ZLTextAlignmentType alignmentType() const; + void setAlignmentType(ZLTextAlignmentType alignmentType); + + unsigned char supportedFontModifier() const; + unsigned char fontModifier() const; + void setFontModifier(FontModifier style, bool set); + + bool isFontSizeMagSupported() const; + signed char fontSizeMag() const; + void setFontSizeMag(signed char fontSizeMag); + + bool isFontFamilySupported() const; + const std::string &fontFamily() const; + void setFontFamily(const std::string &fontFamily); + +private: + unsigned int myMask; + + LengthType myLengths[NUMBER_OF_LENGTHS]; + + ZLTextAlignmentType myAlignmentType; + unsigned char mySupportedFontModifier; + unsigned char myFontModifier; + signed char myFontSizeMag; + std::string myFontFamily; + +friend class ZLTextModel; +}; + +inline ZLTextStyleEntry::ZLTextStyleEntry() : myMask(0), myAlignmentType(ALIGN_UNDEFINED), mySupportedFontModifier(0), myFontModifier(0), myFontSizeMag(0) {} +inline ZLTextStyleEntry::~ZLTextStyleEntry() {} + +inline ZLTextStyleEntry::Metrics::Metrics(int fontSize, int fontXHeight, int fullWidth, int fullHeight) : FontSize(fontSize), FontXHeight(fontXHeight), FullWidth(fullWidth), FullHeight(fullHeight) {} + +inline bool ZLTextStyleEntry::isEmpty() const { return myMask == 0; } + +inline bool ZLTextStyleEntry::isLengthSupported(Length name) const { return (myMask & (1U << name)) != 0; } +inline void ZLTextStyleEntry::setLength(Length name, short length, SizeUnit unit) { + myLengths[name].Size = length; + myLengths[name].Unit = unit; + myMask |= 1U << name; +} + +inline bool ZLTextStyleEntry::isAlignmentTypeSupported() const { return (myMask & SUPPORTS_ALIGNMENT_TYPE) == SUPPORTS_ALIGNMENT_TYPE; } +inline ZLTextAlignmentType ZLTextStyleEntry::alignmentType() const { return myAlignmentType; } +inline void ZLTextStyleEntry::setAlignmentType(ZLTextAlignmentType alignmentType) { myAlignmentType = alignmentType; myMask |= SUPPORTS_ALIGNMENT_TYPE; } + +inline unsigned char ZLTextStyleEntry::supportedFontModifier() const { return mySupportedFontModifier; } +inline unsigned char ZLTextStyleEntry::fontModifier() const { return myFontModifier; } +inline void ZLTextStyleEntry::setFontModifier(FontModifier style, bool set) { + if (set) { + myFontModifier |= style; + } else { + myFontModifier &= ~style; + } + mySupportedFontModifier |= style; +} + +inline bool ZLTextStyleEntry::isFontSizeMagSupported() const { return (myMask & SUPPORTS_FONT_SIZE_MAG) == SUPPORTS_FONT_SIZE_MAG; } +inline signed char ZLTextStyleEntry::fontSizeMag() const { return myFontSizeMag; } +inline void ZLTextStyleEntry::setFontSizeMag(signed char fontSizeMag) { myFontSizeMag = fontSizeMag; myMask |= SUPPORTS_FONT_SIZE_MAG; } + +inline bool ZLTextStyleEntry::isFontFamilySupported() const { return (myMask & SUPPORTS_FONT_FAMILY) == SUPPORTS_FONT_FAMILY; } +inline const std::string &ZLTextStyleEntry::fontFamily() const { return myFontFamily; } +inline void ZLTextStyleEntry::setFontFamily(const std::string &fontFamily) { myFontFamily = fontFamily; myMask |= SUPPORTS_FONT_FAMILY; } + +#endif /* __ZLTEXTSTYLEENTRY_H__ */