Пример #1
0
void ZLTextModel::addControl(const ZLTextStyleEntry &entry) {
	int len = sizeof(int) + 5 + ZLTextStyleEntry::NUMBER_OF_LENGTHS * (sizeof(short) + 1);
	if (entry.fontFamilySupported()) {
		len += entry.fontFamily().length() + 1;
	}
	myLastEntryStart = myAllocator.allocate(len);
	char *address = myLastEntryStart;
	*address++ = ZLTextParagraphEntry::STYLE_ENTRY;
	memcpy(address, &entry.myMask, sizeof(int));
	address += sizeof(int);
	for (int i = 0; i < ZLTextStyleEntry::NUMBER_OF_LENGTHS; ++i) {
		*address++ = entry.myLengths[i].Unit;
		memcpy(address, &entry.myLengths[i].Size, sizeof(short));
		address += sizeof(short);
	}
	*address++ = entry.mySupportedFontModifier;
	*address++ = entry.myFontModifier;
	*address++ = entry.myAlignmentType;
	*address++ = entry.myFontSizeMag;
	if (entry.fontFamilySupported()) {
		memcpy(address, entry.fontFamily().data(), entry.fontFamily().length());
		address += entry.fontFamily().length();
		*address++ = '\0';
	}
	myParagraphs.back()->addEntry(myLastEntryStart);
}
Пример #2
0
void ZLTextModel::addStyleEntry(const ZLTextStyleEntry &entry) {
	// +++ calculating entry size
	std::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)) {
		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++ = entry.entryKind();
	*address++ = 0;
	address = ZLCachedMemoryAllocator::writeUInt16(address, entry.myFeatureMask);

	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;
		}
	}
	if (entry.isFeatureSupported(ZLTextStyleEntry::ALIGNMENT_TYPE)) {
		*address++ = entry.myAlignmentType;
		*address++ = 0;
	}
	if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_FAMILY)) {
		address = ZLCachedMemoryAllocator::writeString(address, fontFamily);
	}
	if (entry.isFeatureSupported(ZLTextStyleEntry::FONT_STYLE_MODIFIER)) {
		*address++ = entry.mySupportedFontModifier;
		*address++ = entry.myFontModifier;
	}
	// --- writing entry

	myParagraphs.back()->addEntry(myLastEntryStart);
	++myParagraphLengths.back();
}