コード例 #1
0
ファイル: DocBookReader.cpp プロジェクト: 37Jayden/bho
std::string DocBookReader::parseLink(ZLUnicodeUtil::Ucs2String s, bool urlencode) {
	//TODO add support for HYPERLINK like that:
	// [0x13] HYPERLINK "http://site.ru/some text" \t "_blank" [0x14] text [0x15]
	//Current implementation search for last QUOTE, so, it reads \t and _blank as part of link
	//Last quote searching is need to handle link like that:
	// [0x13] HYPERLINK "http://yandex.ru/yandsearch?text='some text' и "some text2"" [0x14] link text [0x15]

	static const ZLUnicodeUtil::Ucs2Char QUOTE = 0x22;
	size_t i, first = 0;
	//TODO maybe functions findFirstOf and findLastOf should be in ZLUnicodeUtil class
	for (i = 0; i < s.size(); ++i) {
		if (s.at(i) == QUOTE) {
			first = i;
			break;
		}
	}
	if (i == s.size()) {
		return std::string();
	}
	size_t j, last = 0;
	for (j = s.size(); j > 0 ; --j) {
		if (s.at(j - 1) == QUOTE) {
			last = j - 1;
			break;
		}
	}
	if (j == 0 || last == first) {
		return std::string();
	}

	ZLUnicodeUtil::Ucs2String link;
	for (size_t k = first + 1; k < last; ++k) {
		ZLUnicodeUtil::Ucs2Char ch = s.at(k);
		if (urlencode && ZLUnicodeUtil::isSpace(ch)) {
			//TODO maybe implement function for encoding all signs in url, not only spaces and quotes
			//TODO maybe add backslash support
			link.push_back('%');
			link.push_back('2');
			link.push_back('0');
		} else if (urlencode && ch == QUOTE) {
			link.push_back('%');
			link.push_back('2');
			link.push_back('2');
		} else {
			link.push_back(ch);
		}
	}
	std::string utf8String;
	ZLUnicodeUtil::ucs2ToUtf8(utf8String, link);
	return utf8String;
}
コード例 #2
0
void ZLWin32PaintContext::setFont(const std::string &family, int size, bool bold, bool italic) {
	if (size < 4) {
		size = 4;
	}
	if (myDisplayContext == 0) {
		return;
	}
	// TODO: optimize
	LOGFONT logicalFont;
	memset(&logicalFont, 0, sizeof(LOGFONT));
	logicalFont.lfHeight = size;
	logicalFont.lfWeight = bold ? FW_BOLD : FW_REGULAR;
	logicalFont.lfItalic = italic;
	logicalFont.lfQuality = 5 /*CLEARTYPE_QUALITY*/;
	const int len = std::min((int)family.length(), LF_FACESIZE - 1);
	ZLUnicodeUtil::Ucs2String str;
	ZLUnicodeUtil::utf8ToUcs2(str, family.data(), len);
	str.push_back(0);
	memcpy(logicalFont.lfFaceName, ::wchar(str), 2 * str.size());
	HFONT font = CreateFontIndirect(&logicalFont);
	DeleteObject(SelectObject(myDisplayContext, font));

	GetTextMetrics(myDisplayContext, &myTextMetric);
	mySpaceWidth = -1;
}
コード例 #3
0
void ZLWin32ApplicationWindow::setTooltip(TOOLTIPTEXT &tooltip) {
	Toolbar &tb = toolbar(isFullscreen() ? FULLSCREEN_TOOLBAR : WINDOW_TOOLBAR);
	if (tb.hwnd == 0) {
		return;
	}
	ZLToolbar::ItemPtr item = tb.TBItemByActionCode[tooltip.hdr.idFrom];
	if (!item.isNull()) {
		const ZLToolbar::AbstractButtonItem &button =
			(const ZLToolbar::AbstractButtonItem&)*item;
		ZLUnicodeUtil::Ucs2String tooltipBuffer;
		::createNTWCHARString(tooltipBuffer, button.tooltip());
		size_t length = std::max(tooltipBuffer.size(), (size_t)80);
		memcpy((char*)tooltip.szText, (char*)::wchar(tooltipBuffer), 2 * length);
		tooltip.uFlags = TTF_DI_SETITEM;
	}
}
コード例 #4
0
void ZLQtPaintContext::drawString(int x, int y, const char *str, int len, bool rtl) {
	if (rtl) {
		static ZLUnicodeUtil::Ucs2String ucs2Str;
		ucs2Str.clear();
		ZLUnicodeUtil::utf8ToUcs2(ucs2Str, str, len);
		QString qStr;
		FriBidiChar ch;
		for (int i = ucs2Str.size() - 1; i >= 0; --i) {
			fribidi_get_mirror_char(ucs2Str[i], &ch);
			qStr.append(QChar(ch));
		}
		myPainter->drawText(x, y, qStr);
	} else {
		QString qStr = QString::fromUtf8(str, len);
		myPainter->drawText(x, y, qStr);
	}
}
コード例 #5
0
ファイル: ZLTextModel.cpp プロジェクト: MastAvalons/FBReaderJ
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();
}