mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
style entry writing to the model cache
This commit is contained in:
parent
2422f080a8
commit
74cb4cf7be
11 changed files with 234 additions and 180 deletions
|
@ -70,7 +70,7 @@ static void parseLength(const std::string &toParse, short &size, ZLTextStyleEntr
|
|||
}
|
||||
}
|
||||
|
||||
void StyleSheetTable::setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Length name, const AttributeMap &map, const std::string &attributeName) {
|
||||
void StyleSheetTable::setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Feature fetureId, const AttributeMap &map, const std::string &attributeName) {
|
||||
StyleSheetTable::AttributeMap::const_iterator it = map.find(attributeName);
|
||||
if (it == map.end()) {
|
||||
return;
|
||||
|
@ -80,7 +80,7 @@ void StyleSheetTable::setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Lengt
|
|||
short size;
|
||||
ZLTextStyleEntry::SizeUnit unit;
|
||||
parseLength(values[0], size, unit);
|
||||
entry.setLength(name, size, unit);
|
||||
entry.setLength(fetureId, size, unit);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,19 +190,19 @@ shared_ptr<ZLTextStyleEntry> StyleSheetTable::createControl(const AttributeMap &
|
|||
const std::vector<std::string> &fontSize = values(styles, "font-size");
|
||||
if (!fontSize.empty()) {
|
||||
if (fontSize[0] == "xx-small") {
|
||||
entry->setFontSizeMag(-3);
|
||||
entry->setFontSizeMagnification(-3);
|
||||
} else if (fontSize[0] == "x-small") {
|
||||
entry->setFontSizeMag(-2);
|
||||
entry->setFontSizeMagnification(-2);
|
||||
} else if (fontSize[0] == "small") {
|
||||
entry->setFontSizeMag(-1);
|
||||
entry->setFontSizeMagnification(-1);
|
||||
} else if (fontSize[0] == "medium") {
|
||||
entry->setFontSizeMag(0);
|
||||
entry->setFontSizeMagnification(0);
|
||||
} else if (fontSize[0] == "large") {
|
||||
entry->setFontSizeMag(1);
|
||||
entry->setFontSizeMagnification(1);
|
||||
} else if (fontSize[0] == "x-large") {
|
||||
entry->setFontSizeMag(2);
|
||||
entry->setFontSizeMagnification(2);
|
||||
} else if (fontSize[0] == "xx-large") {
|
||||
entry->setFontSizeMag(3);
|
||||
entry->setFontSizeMagnification(3);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
private:
|
||||
void addMap(const std::string &tag, const std::string &aClass, const AttributeMap &map);
|
||||
|
||||
static void setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Length name, const AttributeMap &map, const std::string &attributeName);
|
||||
static void setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Feature featureId, const AttributeMap &map, const std::string &attributeName);
|
||||
static const std::vector<std::string> &values(const AttributeMap &map, const std::string &name);
|
||||
|
||||
public:
|
||||
|
|
|
@ -585,7 +585,7 @@ void XHTMLReader::beginParagraph() {
|
|||
myModelReader.addControl(**it);
|
||||
doBlockSpaceBefore =
|
||||
doBlockSpaceBefore ||
|
||||
(*it)->isLengthSupported(ZLTextStyleEntry::LENGTH_SPACE_BEFORE);
|
||||
(*it)->isFeatureSupported(ZLTextStyleEntry::LENGTH_SPACE_BEFORE);
|
||||
}
|
||||
|
||||
if (doBlockSpaceBefore) {
|
||||
|
@ -604,7 +604,7 @@ void XHTMLReader::endParagraph() {
|
|||
for (std::vector<shared_ptr<ZLTextStyleEntry> >::const_iterator it = myStyleEntryStack.begin(); it != myStyleEntryStack.end() - myStylesToRemove; ++it) {
|
||||
doBlockSpaceAfter =
|
||||
doBlockSpaceAfter ||
|
||||
(*it)->isLengthSupported(ZLTextStyleEntry::LENGTH_SPACE_AFTER);
|
||||
(*it)->isFeatureSupported(ZLTextStyleEntry::LENGTH_SPACE_AFTER);
|
||||
}
|
||||
if (doBlockSpaceAfter) {
|
||||
ZLTextStyleEntry blockingEntry;
|
||||
|
|
29
jni/NativeFormats/zlibrary/core/src/util/ZLBoolean3.h
Normal file
29
jni/NativeFormats/zlibrary/core/src/util/ZLBoolean3.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 __ZLBOOLEAN3_H__
|
||||
#define __ZLBOOLEAN3_H__
|
||||
|
||||
enum ZLBoolean3 {
|
||||
B3_FALSE = 0,
|
||||
B3_TRUE = 1,
|
||||
B3_UNDEFINED = 2
|
||||
};
|
||||
|
||||
#endif /* __ZLBOOLEAN3_H__ */
|
|
@ -25,9 +25,12 @@
|
|||
//#include <ZLSearchUtil.h>
|
||||
//#include <ZLLanguageUtil.h>
|
||||
#include <ZLUnicodeUtil.h>
|
||||
//#include <ZLStringUtil.h>
|
||||
//#include <ZLLogger.h>
|
||||
|
||||
#include "ZLTextModel.h"
|
||||
#include "ZLTextParagraph.h"
|
||||
#include "ZLTextStyleEntry.h"
|
||||
|
||||
ZLTextModel::ZLTextModel(const std::string &id, const std::string &language, const size_t rowSize,
|
||||
const std::string &directoryName, const std::string &fileExtension) :
|
||||
|
@ -265,65 +268,73 @@ void ZLTextModel::addControl(ZLTextKind textKind, bool isStart) {
|
|||
++myParagraphLengths.back();
|
||||
}
|
||||
|
||||
//static int EntryCount = 0;
|
||||
//static int EntryLen = 0;
|
||||
|
||||
void ZLTextModel::addControl(const ZLTextStyleEntry &entry) {
|
||||
/*
|
||||
size_t len = 10 + 2 * (ZLTextStyleEntry::NUMBER_OF_LENGTHS +
|
||||
(ZLTextStyleEntry::NUMBER_OF_LENGTHS + 1) / 2);
|
||||
|
||||
ZLUnicodeUtil::Ucs2String fontFamily;
|
||||
size_t fontFamilyLen = 0;
|
||||
if (entry.fontFamilySupported()) {
|
||||
ZLUnicodeUtil::utf8ToUcs2(fontFamily, entry.fontFamily());
|
||||
fontFamilyLen = fontFamily.size() * 2;
|
||||
len += 2 + fontFamilyLen;
|
||||
// +++ calculating entry size
|
||||
size_t len = 4; // entry type + feature mask
|
||||
for (int i = 0; i < ZLTextStyleEntry::NUMBER_OF_LENGTHS; ++i) {
|
||||
if (entry.isFeatureSupported((ZLTextStyleEntry::Feature)i)) {
|
||||
len += 4; // each supported length
|
||||
}
|
||||
}
|
||||
if (entry.isFeatureSupported(ZLTextStyleEntry::ALIGNMENT_TYPE) ||
|
||||
entry.isFeatureSupported(ZLTextStyleEntry::FONT_SIZE_MAGNIFICATION)) {
|
||||
len += 2;
|
||||
}
|
||||
ZLUnicodeUtil::Ucs2String fontFamily;
|
||||
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) {
|
||||
ZLUnicodeUtil::utf8ToUcs2(fontFamily, entry.fontFamily());
|
||||
len += 2 + fontFamily.size() * 2;
|
||||
}
|
||||
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) {
|
||||
len += 2;
|
||||
}
|
||||
// --- calculating entry size
|
||||
|
||||
/*
|
||||
EntryCount += 1;
|
||||
EntryLen += len;
|
||||
std::string debug = "style entry counter: ";
|
||||
ZLStringUtil::appendNumber(debug, EntryCount);
|
||||
debug += "/";
|
||||
ZLStringUtil::appendNumber(debug, EntryLen);
|
||||
ZLLogger::Instance().println(ZLLogger::DEFAULT_CLASS, debug);
|
||||
*/
|
||||
|
||||
// +++ writing entry
|
||||
myLastEntryStart = myAllocator->allocate(len);
|
||||
char *address = myLastEntryStart;
|
||||
|
||||
*address++ = ZLTextParagraphEntry::STYLE_ENTRY;
|
||||
*address++ = 0;
|
||||
address = ZLCachedMemoryAllocator::writeUInt16(address, entry.myFeatureMask);
|
||||
|
||||
ZLCachedMemoryAllocator::writeUInt32(address, entry.myMask);
|
||||
address += 4;
|
||||
|
||||
// Pack myLengths array in following manner:
|
||||
//
|
||||
// 1) for each two elements there is a word with those Units (two Units
|
||||
// in two bytes) followed by two words with those Sizes;
|
||||
//
|
||||
// 2) if myLengths.size() is odd (that means the last element has no paired one)
|
||||
// one more word is appended with only one Unit (in the first byte) followed by
|
||||
// a word containing corresponding Size.
|
||||
//
|
||||
for (int i = 0; i < ZLTextStyleEntry::NUMBER_OF_LENGTHS - 1; i += 2) {
|
||||
const ZLTextStyleEntry::LengthType &l0 = entry.myLengths[i];
|
||||
const ZLTextStyleEntry::LengthType &l1 = entry.myLengths[i + 1];
|
||||
*address++ = l0.Unit;
|
||||
*address++ = l1.Unit;
|
||||
ZLCachedMemoryAllocator::writeUInt16(address, l0.Size);
|
||||
address += 2;
|
||||
ZLCachedMemoryAllocator::writeUInt16(address, l1.Size);
|
||||
address += 2;
|
||||
}
|
||||
if (ZLTextStyleEntry::NUMBER_OF_LENGTHS % 2 == 1) {
|
||||
const ZLTextStyleEntry::LengthType &l0 = entry.myLengths[ZLTextStyleEntry::NUMBER_OF_LENGTHS - 1];
|
||||
*address++ = l0.Unit;
|
||||
for (int i = 0; i < ZLTextStyleEntry::NUMBER_OF_LENGTHS; ++i) {
|
||||
if (entry.isFeatureSupported((ZLTextStyleEntry::Feature)i)) {
|
||||
const ZLTextStyleEntry::LengthType &len = entry.myLengths[i];
|
||||
address = ZLCachedMemoryAllocator::writeUInt16(address, len.Size);
|
||||
*address++ = len.Unit;
|
||||
*address++ = 0;
|
||||
ZLCachedMemoryAllocator::writeUInt16(address, l0.Size);
|
||||
address += 2;
|
||||
}
|
||||
}
|
||||
if (entry.isFeatureSupported(ZLTextStyleEntry::ALIGNMENT_TYPE) ||
|
||||
entry.isFeatureSupported(ZLTextStyleEntry::FONT_SIZE_MAGNIFICATION)) {
|
||||
*address++ = entry.myAlignmentType;
|
||||
*address++ = entry.myFontSizeMagnification;
|
||||
}
|
||||
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) {
|
||||
address = ZLCachedMemoryAllocator::writeString(address, fontFamily);
|
||||
}
|
||||
if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) {
|
||||
*address++ = entry.mySupportedFontModifier;
|
||||
*address++ = entry.myFontModifier;
|
||||
*address++ = entry.myAlignmentType;
|
||||
*address++ = entry.myFontSizeMag;
|
||||
if (entry.fontFamilySupported()) {
|
||||
ZLCachedMemoryAllocator::writeUInt16(address, fontFamily.size());
|
||||
memcpy(address + 2, &fontFamily.front(), fontFamilyLen);
|
||||
}
|
||||
// --- writing entry
|
||||
|
||||
myParagraphs.back()->addEntry(myLastEntryStart);
|
||||
++myParagraphLengths.back();
|
||||
*/
|
||||
}
|
||||
|
||||
void ZLTextModel::addHyperlinkControl(ZLTextKind textKind, ZLHyperlinkType hyperlinkType, const std::string &label) {
|
||||
|
|
|
@ -30,32 +30,33 @@
|
|||
|
||||
const shared_ptr<ZLTextParagraphEntry> ResetBidiEntry::Instance = new ResetBidiEntry();
|
||||
|
||||
short ZLTextStyleEntry::length(Length name, const Metrics &metrics) const {
|
||||
switch (myLengths[name].Unit) {
|
||||
short ZLTextStyleEntry::length(Feature featureId, const Metrics &metrics) const {
|
||||
switch (myLengths[featureId].Unit) {
|
||||
default:
|
||||
case SIZE_UNIT_PIXEL:
|
||||
return myLengths[name].Size;
|
||||
return myLengths[featureId].Size;
|
||||
case SIZE_UNIT_EM_100:
|
||||
return (myLengths[name].Size * metrics.FontSize + 50) / 100;
|
||||
return (myLengths[featureId].Size * metrics.FontSize + 50) / 100;
|
||||
case SIZE_UNIT_EX_100:
|
||||
return (myLengths[name].Size * metrics.FontXHeight + 50) / 100;
|
||||
return (myLengths[featureId].Size * metrics.FontXHeight + 50) / 100;
|
||||
case SIZE_UNIT_PERCENT:
|
||||
switch (name) {
|
||||
switch (featureId) {
|
||||
default:
|
||||
case LENGTH_LEFT_INDENT:
|
||||
case LENGTH_RIGHT_INDENT:
|
||||
case LENGTH_FIRST_LINE_INDENT_DELTA:
|
||||
return (myLengths[name].Size * metrics.FullWidth + 50) / 100;
|
||||
return (myLengths[featureId].Size * metrics.FullWidth + 50) / 100;
|
||||
case LENGTH_SPACE_BEFORE:
|
||||
case LENGTH_SPACE_AFTER:
|
||||
return (myLengths[name].Size * metrics.FullHeight + 50) / 100;
|
||||
return (myLengths[featureId].Size * metrics.FullHeight + 50) / 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
ZLTextStyleEntry::ZLTextStyleEntry(char *address) {
|
||||
myMask = ZLCachedMemoryAllocator::readUInt32(address);
|
||||
address += 4;
|
||||
myFeatureMask = ZLCachedMemoryAllocator::readUInt16(address);
|
||||
address += 2;
|
||||
|
||||
const int lengthMinusOne = ZLTextStyleEntry::NUMBER_OF_LENGTHS - 1;
|
||||
for (int i = 0; i < lengthMinusOne; i += 2) {
|
||||
|
@ -78,14 +79,15 @@ ZLTextStyleEntry::ZLTextStyleEntry(char *address) {
|
|||
mySupportedFontModifier = *address++;
|
||||
myFontModifier = *address++;
|
||||
myAlignmentType = (ZLTextAlignmentType)*address++;
|
||||
myFontSizeMag = *address++;
|
||||
if (isFontFamilySupported()) {
|
||||
myFontSizeMagnification = *address++;
|
||||
if (isFeatureSupported(FONT_FAMILY)) {
|
||||
const size_t len = ZLCachedMemoryAllocator::readUInt16(address);
|
||||
ZLUnicodeUtil::Ucs2Char *ucs2data = (ZLUnicodeUtil::Ucs2Char *)(address + 2);
|
||||
ZLUnicodeUtil::Ucs2String ucs2str(ucs2data, ucs2data + len);
|
||||
ZLUnicodeUtil::ucs2ToUtf8(myFontFamily, ucs2str);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
ZLTextControlEntryPool ZLTextControlEntryPool::Pool;
|
||||
|
||||
|
@ -100,6 +102,7 @@ shared_ptr<ZLTextParagraphEntry> ZLTextControlEntryPool::controlEntry(ZLTextKind
|
|||
return entry;
|
||||
}
|
||||
|
||||
/*
|
||||
ZLTextHyperlinkControlEntry::ZLTextHyperlinkControlEntry(const char *address) : ZLTextControlEntry((ZLTextKind)*address, true), myHyperlinkType((ZLHyperlinkType)*(address + 1)) {
|
||||
const size_t len = ZLCachedMemoryAllocator::readUInt16(address + 2);
|
||||
ZLUnicodeUtil::Ucs2Char *ucs2data = (ZLUnicodeUtil::Ucs2Char *)(address + 4);
|
||||
|
@ -122,7 +125,6 @@ ImageEntry::ImageEntry(const char *address) {
|
|||
ZLUnicodeUtil::ucs2ToUtf8(myId, ucs2str);
|
||||
}
|
||||
|
||||
|
||||
const shared_ptr<ZLTextParagraphEntry> ZLTextParagraph::Iterator::entry() const {
|
||||
if (myEntry.isNull()) {
|
||||
switch (*myPointer) {
|
||||
|
@ -182,7 +184,7 @@ void ZLTextParagraph::Iterator::next() {
|
|||
case ZLTextParagraphEntry::STYLE_ENTRY:
|
||||
{
|
||||
unsigned int mask = ZLCachedMemoryAllocator::readUInt32(myPointer + 2);
|
||||
bool withFontFamily = (mask & ZLTextStyleEntry::SUPPORTS_FONT_FAMILY) == ZLTextStyleEntry::SUPPORTS_FONT_FAMILY;
|
||||
bool withFontFamily = (mask & (1 << ZLTextStyleEntry::FONT_FAMILY)) != 0;
|
||||
|
||||
myPointer += 10 + 2 * (ZLTextStyleEntry::NUMBER_OF_LENGTHS +
|
||||
(ZLTextStyleEntry::NUMBER_OF_LENGTHS + 1) / 2);
|
||||
|
@ -234,7 +236,7 @@ size_t ZLTextParagraph::characterNumber() const {
|
|||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
ZLTextTreeParagraph::ZLTextTreeParagraph(ZLTextTreeParagraph *parent) : myIsOpen(false), myParent(parent) {
|
||||
if (parent != 0) {
|
||||
|
|
|
@ -103,7 +103,7 @@ private:
|
|||
class ZLTextHyperlinkControlEntry : public ZLTextControlEntry {
|
||||
|
||||
public:
|
||||
ZLTextHyperlinkControlEntry(const char *address);
|
||||
//ZLTextHyperlinkControlEntry(const char *address);
|
||||
~ZLTextHyperlinkControlEntry();
|
||||
const std::string &label() const;
|
||||
ZLHyperlinkType hyperlinkType() const;
|
||||
|
@ -117,7 +117,7 @@ private:
|
|||
class ZLTextEntry : public ZLTextParagraphEntry {
|
||||
|
||||
public:
|
||||
ZLTextEntry(const char *address);
|
||||
//ZLTextEntry(const char *address);
|
||||
~ZLTextEntry();
|
||||
|
||||
size_t dataLength() const;
|
||||
|
@ -130,7 +130,7 @@ private:
|
|||
class ImageEntry : public ZLTextParagraphEntry {
|
||||
|
||||
public:
|
||||
ImageEntry(const char *address);
|
||||
//ImageEntry(const char *address);
|
||||
~ImageEntry();
|
||||
const std::string &id() const;
|
||||
short vOffset() const;
|
||||
|
@ -152,6 +152,7 @@ private:
|
|||
class ZLTextParagraph {
|
||||
|
||||
public:
|
||||
/*
|
||||
class Iterator {
|
||||
|
||||
public:
|
||||
|
@ -169,6 +170,7 @@ public:
|
|||
size_t myEndIndex;
|
||||
mutable shared_ptr<ZLTextParagraphEntry> myEntry;
|
||||
};
|
||||
*/
|
||||
|
||||
enum Kind {
|
||||
TEXT_PARAGRAPH,
|
||||
|
@ -189,8 +191,8 @@ public:
|
|||
|
||||
size_t entryNumber() const;
|
||||
|
||||
size_t textDataLength() const;
|
||||
size_t characterNumber() const;
|
||||
//size_t textDataLength() const;
|
||||
//size_t characterNumber() const;
|
||||
|
||||
private:
|
||||
void addEntry(char *address);
|
||||
|
@ -283,10 +285,10 @@ inline ZLTextParagraph::Kind ZLTextParagraph::kind() const { return TEXT_PARAGRA
|
|||
inline size_t ZLTextParagraph::entryNumber() const { return myEntryNumber; }
|
||||
inline void ZLTextParagraph::addEntry(char *address) { if (myEntryNumber == 0) myFirstEntryAddress = address; ++myEntryNumber; }
|
||||
|
||||
inline ZLTextParagraph::Iterator::Iterator(const ZLTextParagraph ¶graph) : myPointer(paragraph.myFirstEntryAddress), myIndex(0), myEndIndex(paragraph.entryNumber()) {}
|
||||
inline ZLTextParagraph::Iterator::~Iterator() {}
|
||||
inline bool ZLTextParagraph::Iterator::isEnd() const { return myIndex == myEndIndex; }
|
||||
inline ZLTextParagraphEntry::Kind ZLTextParagraph::Iterator::entryKind() const { return (ZLTextParagraphEntry::Kind)*myPointer; }
|
||||
//inline ZLTextParagraph::Iterator::Iterator(const ZLTextParagraph ¶graph) : myPointer(paragraph.myFirstEntryAddress), myIndex(0), myEndIndex(paragraph.entryNumber()) {}
|
||||
//inline ZLTextParagraph::Iterator::~Iterator() {}
|
||||
//inline bool ZLTextParagraph::Iterator::isEnd() const { return myIndex == myEndIndex; }
|
||||
//inline ZLTextParagraphEntry::Kind ZLTextParagraph::Iterator::entryKind() const { return (ZLTextParagraphEntry::Kind)*myPointer; }
|
||||
|
||||
inline ZLTextSpecialParagraph::ZLTextSpecialParagraph(Kind kind) : myKind(kind) {}
|
||||
inline ZLTextSpecialParagraph::~ZLTextSpecialParagraph() {}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include <ZLTextParagraph.h>
|
||||
#include <ZLTextAlignmentType.h>
|
||||
#include <ZLBoolean3.h>
|
||||
|
||||
class ZLTextStyleEntry : public ZLTextParagraphEntry {
|
||||
|
||||
|
@ -45,7 +46,6 @@ public:
|
|||
};
|
||||
|
||||
enum FontModifier {
|
||||
FONT_MODIFIER_DEFAULT = 0,
|
||||
FONT_MODIFIER_BOLD = 1 << 0,
|
||||
FONT_MODIFIER_ITALIC = 1 << 1,
|
||||
FONT_MODIFIER_UNDERLINED = 1 << 2,
|
||||
|
@ -53,19 +53,19 @@ public:
|
|||
FONT_MODIFIER_SMALLCAPS = 1 << 4,
|
||||
};
|
||||
|
||||
enum Length {
|
||||
enum Feature {
|
||||
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,
|
||||
ALIGNMENT_TYPE = NUMBER_OF_LENGTHS,
|
||||
FONT_SIZE_MAGNIFICATION = NUMBER_OF_LENGTHS + 1,
|
||||
FONT_FAMILY = NUMBER_OF_LENGTHS + 2,
|
||||
FONT_STYLE_MODIFIER = NUMBER_OF_LENGTHS + 3,
|
||||
};
|
||||
|
||||
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;
|
||||
|
@ -74,80 +74,88 @@ private:
|
|||
|
||||
public:
|
||||
ZLTextStyleEntry();
|
||||
ZLTextStyleEntry(char *address);
|
||||
//ZLTextStyleEntry(char *address);
|
||||
~ZLTextStyleEntry();
|
||||
|
||||
bool isEmpty() const;
|
||||
bool isFeatureSupported(Feature featureId) const;
|
||||
|
||||
bool isLengthSupported(Length name) const;
|
||||
short length(Length name, const Metrics &metrics) const;
|
||||
void setLength(Length name, short length, SizeUnit unit);
|
||||
short length(Feature featureId, const Metrics &metrics) const;
|
||||
void setLength(Feature featureId, 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);
|
||||
ZLBoolean3 fontModifier(FontModifier modifier) const;
|
||||
void setFontModifier(FontModifier modifier, bool on);
|
||||
|
||||
bool isFontSizeMagSupported() const;
|
||||
signed char fontSizeMag() const;
|
||||
void setFontSizeMag(signed char fontSizeMag);
|
||||
signed char fontSizeMagnification() const;
|
||||
void setFontSizeMagnification(signed char fontSizeMagnification);
|
||||
|
||||
bool isFontFamilySupported() const;
|
||||
const std::string &fontFamily() const;
|
||||
void setFontFamily(const std::string &fontFamily);
|
||||
|
||||
private:
|
||||
unsigned int myMask;
|
||||
unsigned short myFeatureMask;
|
||||
|
||||
LengthType myLengths[NUMBER_OF_LENGTHS];
|
||||
|
||||
ZLTextAlignmentType myAlignmentType;
|
||||
unsigned char mySupportedFontModifier;
|
||||
unsigned char myFontModifier;
|
||||
signed char myFontSizeMag;
|
||||
signed char myFontSizeMagnification;
|
||||
std::string myFontFamily;
|
||||
|
||||
friend class ZLTextModel;
|
||||
};
|
||||
|
||||
inline ZLTextStyleEntry::ZLTextStyleEntry() : myMask(0), myAlignmentType(ALIGN_UNDEFINED), mySupportedFontModifier(0), myFontModifier(0), myFontSizeMag(0) {}
|
||||
inline ZLTextStyleEntry::ZLTextStyleEntry() : myFeatureMask(0), myAlignmentType(ALIGN_UNDEFINED), mySupportedFontModifier(0), myFontModifier(0), myFontSizeMagnification(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::isEmpty() const { return myFeatureMask == 0; }
|
||||
inline bool ZLTextStyleEntry::isFeatureSupported(Feature featureId) const {
|
||||
return (myFeatureMask & (1 << featureId)) != 0;
|
||||
}
|
||||
|
||||
inline void ZLTextStyleEntry::setLength(Feature featureId, short length, SizeUnit unit) {
|
||||
myFeatureMask |= 1 << featureId;
|
||||
myLengths[featureId].Size = length;
|
||||
myLengths[featureId].Unit = unit;
|
||||
}
|
||||
|
||||
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 void ZLTextStyleEntry::setAlignmentType(ZLTextAlignmentType alignmentType) {
|
||||
myFeatureMask |= 1 << ALIGNMENT_TYPE;
|
||||
myAlignmentType = alignmentType;
|
||||
}
|
||||
|
||||
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;
|
||||
inline ZLBoolean3 ZLTextStyleEntry::fontModifier(FontModifier modifier) const {
|
||||
if ((mySupportedFontModifier & modifier) == 0) {
|
||||
return B3_UNDEFINED;
|
||||
}
|
||||
return (myFontModifier & modifier) == 0 ? B3_FALSE : B3_TRUE;
|
||||
}
|
||||
inline void ZLTextStyleEntry::setFontModifier(FontModifier modifier, bool on) {
|
||||
myFeatureMask |= FONT_STYLE_MODIFIER;
|
||||
mySupportedFontModifier |= modifier;
|
||||
if (on) {
|
||||
myFontModifier |= modifier;
|
||||
} else {
|
||||
myFontModifier &= ~style;
|
||||
myFontModifier &= ~modifier;
|
||||
}
|
||||
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 signed char ZLTextStyleEntry::fontSizeMagnification() const { return myFontSizeMagnification; }
|
||||
inline void ZLTextStyleEntry::setFontSizeMagnification(signed char fontSizeMagnification) {
|
||||
myFeatureMask |= FONT_SIZE_MAGNIFICATION;
|
||||
myFontSizeMagnification = fontSizeMagnification;
|
||||
}
|
||||
|
||||
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 void ZLTextStyleEntry::setFontFamily(const std::string &fontFamily) {
|
||||
myFeatureMask |= FONT_FAMILY;
|
||||
myFontFamily = fontFamily;
|
||||
}
|
||||
|
||||
#endif /* __ZLTEXTSTYLEENTRY_H__ */
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.*;
|
|||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
import org.geometerplus.zlibrary.core.util.*;
|
||||
|
||||
public class ZLTextPlainModel implements ZLTextModel {
|
||||
public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
||||
private final String myId;
|
||||
private final String myLanguage;
|
||||
|
||||
|
@ -184,20 +184,30 @@ public class ZLTextPlainModel implements ZLTextModel {
|
|||
break;
|
||||
case ZLTextParagraph.Entry.STYLE:
|
||||
{
|
||||
final int mask = (int)data[dataOffset++];
|
||||
final ZLTextStyleEntry entry = new ZLTextStyleEntry();
|
||||
if ((mask & ZLTextStyleEntry.SUPPORTS_LEFT_INDENT) ==
|
||||
ZLTextStyleEntry.SUPPORTS_LEFT_INDENT) {
|
||||
entry.setLeftIndent((short)data[dataOffset++]);
|
||||
|
||||
final short mask = (short)data[dataOffset++];
|
||||
for (int i = 0; i < NUMBER_OF_LENGTHS; ++i) {
|
||||
if (ZLTextStyleEntry.isFeatureSupported(mask, i)) {
|
||||
// TODO: read length
|
||||
dataOffset += 2;
|
||||
}
|
||||
if ((mask & ZLTextStyleEntry.SUPPORTS_RIGHT_INDENT) ==
|
||||
ZLTextStyleEntry.SUPPORTS_RIGHT_INDENT) {
|
||||
entry.setRightIndent((short)data[dataOffset++]);
|
||||
}
|
||||
if ((mask & ZLTextStyleEntry.SUPPORTS_ALIGNMENT_TYPE) ==
|
||||
ZLTextStyleEntry.SUPPORTS_ALIGNMENT_TYPE) {
|
||||
entry.setAlignmentType((byte)data[dataOffset++]);
|
||||
if (ZLTextStyleEntry.isFeatureSupported(mask, ALIGNMENT_TYPE) ||
|
||||
ZLTextStyleEntry.isFeatureSupported(mask, FONT_SIZE_MAGNIFICATION)) {
|
||||
// TODO: read alignment type and/or font size magnification
|
||||
dataOffset += 1;
|
||||
}
|
||||
if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_FAMILY)) {
|
||||
final short familyLength = (short)data[dataOffset++];
|
||||
// TODO: read font family
|
||||
dataOffset += familyLength;
|
||||
}
|
||||
if (ZLTextStyleEntry.isFeatureSupported(mask, FONT_STYLE_MODIFIER)) {
|
||||
// TODO: read font modifiers
|
||||
dataOffset += 1;
|
||||
}
|
||||
|
||||
myStyleEntry = entry;
|
||||
}
|
||||
case ZLTextParagraph.Entry.RESET_BIDI:
|
||||
|
|
|
@ -20,58 +20,47 @@
|
|||
package org.geometerplus.zlibrary.text.model;
|
||||
|
||||
public final class ZLTextStyleEntry {
|
||||
final static short SUPPORTS_LEFT_INDENT = 1 << 0;
|
||||
final static short SUPPORTS_RIGHT_INDENT = 1 << 1;
|
||||
final static short SUPPORTS_ALIGNMENT_TYPE = 1 << 2;
|
||||
interface Feature {
|
||||
int LENGTH_LEFT_INDENT = 0;
|
||||
int LENGTH_RIGHT_INDENT = 1;
|
||||
int LENGTH_FIRST_LINE_INDENT_DELTA = 2;
|
||||
int LENGTH_SPACE_BEFORE = 3;
|
||||
int LENGTH_SPACE_AFTER = 4;
|
||||
int NUMBER_OF_LENGTHS = 5;
|
||||
int ALIGNMENT_TYPE = NUMBER_OF_LENGTHS;
|
||||
int FONT_SIZE_MAGNIFICATION = NUMBER_OF_LENGTHS + 1;
|
||||
int FONT_FAMILY = NUMBER_OF_LENGTHS + 2;
|
||||
int FONT_STYLE_MODIFIER = NUMBER_OF_LENGTHS + 3;
|
||||
}
|
||||
|
||||
private short myMask;
|
||||
private short myLeftIndent;
|
||||
private short myRightIndent;
|
||||
private byte myAlignmentType;
|
||||
private short myFeatureMask;
|
||||
|
||||
static boolean isFeatureSupported(short mask, int featureId) {
|
||||
return (mask & (1 << featureId)) != 0;
|
||||
}
|
||||
|
||||
public boolean isFeatureSupported(int featureId) {
|
||||
return isFeatureSupported(myFeatureMask, featureId);
|
||||
}
|
||||
|
||||
//private short myLeftIndent;
|
||||
//private short myRightIndent;
|
||||
//private byte myAlignmentType;
|
||||
|
||||
public ZLTextStyleEntry() {
|
||||
}
|
||||
|
||||
short getMask() {
|
||||
return myMask;
|
||||
}
|
||||
|
||||
public boolean isLeftIndentSupported() {
|
||||
return (myMask & SUPPORTS_LEFT_INDENT) == SUPPORTS_LEFT_INDENT;
|
||||
}
|
||||
|
||||
/*
|
||||
public short getLeftIndent() {
|
||||
return myLeftIndent;
|
||||
}
|
||||
|
||||
public void setLeftIndent(short leftIndent) {
|
||||
myMask |= SUPPORTS_LEFT_INDENT;
|
||||
myLeftIndent = leftIndent;
|
||||
}
|
||||
|
||||
public boolean isRightIndentSupported() {
|
||||
return (myMask & SUPPORTS_RIGHT_INDENT) == SUPPORTS_RIGHT_INDENT;
|
||||
}
|
||||
|
||||
public short getRightIndent() {
|
||||
return myRightIndent;
|
||||
}
|
||||
|
||||
public void setRightIndent(short rightIndent) {
|
||||
myMask |= SUPPORTS_RIGHT_INDENT;
|
||||
myRightIndent = rightIndent;
|
||||
}
|
||||
|
||||
public boolean isAlignmentTypeSupported() {
|
||||
return (myMask & SUPPORTS_ALIGNMENT_TYPE) == SUPPORTS_ALIGNMENT_TYPE;
|
||||
}
|
||||
|
||||
public byte getAlignmentType() {
|
||||
return myAlignmentType;
|
||||
}
|
||||
|
||||
public void setAlignmentType(byte alignmentType) {
|
||||
myMask |= SUPPORTS_ALIGNMENT_TYPE;
|
||||
myAlignmentType = alignmentType;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -132,6 +132,8 @@ public final class ZLTextWritablePlainModel extends ZLTextPlainModel implements
|
|||
}
|
||||
|
||||
public void addStyleEntry(ZLTextStyleEntry entry) {
|
||||
// TODO: implement
|
||||
/*
|
||||
int len = 2;
|
||||
for (int mask = entry.getMask(); mask != 0; mask >>= 1) {
|
||||
len += mask & 1;
|
||||
|
@ -149,6 +151,7 @@ public final class ZLTextWritablePlainModel extends ZLTextPlainModel implements
|
|||
if (entry.isAlignmentTypeSupported()) {
|
||||
block[myBlockOffset++] = (char)entry.getAlignmentType();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public void addFixedHSpace(short length) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue