Esempio n. 1
0
TextBlock::TextBlock(const style::font &font, const QString &str, QFixed minResizeWidth, uint16 from, uint16 length, uchar flags, const style::color &color, uint16 lnkIndex) : ITextBlock(font, str, from, length, flags, color, lnkIndex) {
	_flags |= ((TextBlockTText & 0x0F) << 8);
	if (length) {
		style::font blockFont = font;
		if (!flags && lnkIndex) {
			// should use textStyle lnkFlags somehow... not supported
		}

		if ((flags & TextBlockFPre) || (flags & TextBlockFCode)) {
			blockFont = App::monofont();
			if (blockFont->size() != font->size() || blockFont->flags() != font->flags()) {
				blockFont = style::font(font->size(), font->flags(), blockFont->family());
			}
		} else {
			if (flags & TextBlockFBold) {
				blockFont = blockFont->bold();
			} else if (flags & TextBlockFSemibold) {
				blockFont = st::semiboldFont;
				if (blockFont->size() != font->size() || blockFont->flags() != font->flags()) {
					blockFont = style::font(font->size(), font->flags(), blockFont->family());
				}
			}
			if (flags & TextBlockFItalic) blockFont = blockFont->italic();
			if (flags & TextBlockFUnderline) blockFont = blockFont->underline();
			if (flags & TextBlockFTilde) { // tilde fix in OpenSans
				blockFont = st::semiboldFont;
			}
		}

		QString part = str.mid(_from, length);
		QStackTextEngine engine(part, blockFont->f);
		engine.itemize();

		QTextLayout layout(&engine);
		layout.beginLayout();
		layout.createLine();

		bool logCrashString = (rand_value<uchar>() % 4 == 1);
		if (logCrashString) {
			SignalHandlers::setCrashAnnotationRef("CrashString", &str);
		}
		BlockParser parser(&engine, this, minResizeWidth, _from, part);
		if (logCrashString) {
			SignalHandlers::clearCrashAnnotationRef("CrashString");
		}

		layout.endLayout();
	}
}
Esempio n. 2
0
TextBlock::TextBlock(const style::font &font, const QString &str, QFixed minResizeWidth, uint16 from, uint16 length, uchar flags, uint16 lnkIndex) : ITextBlock(font, str, from, length, flags, lnkIndex) {
	_flags |= ((TextBlockTText & 0x0F) << 8);
	if (length) {
		style::font blockFont = font;
		if (!flags && lnkIndex) {
			// should use TextStyle lnkFlags somehow... not supported
		}

		if ((flags & TextBlockFPre) || (flags & TextBlockFCode)) {
			blockFont = App::monofont();
			if (blockFont->size() != font->size() || blockFont->flags() != font->flags()) {
				blockFont = style::font(font->size(), font->flags(), blockFont->family());
			}
		} else {
			if (flags & TextBlockFBold) {
				blockFont = blockFont->bold();
			} else if (flags & TextBlockFSemibold) {
				blockFont = st::semiboldFont;
				if (blockFont->size() != font->size() || blockFont->flags() != font->flags()) {
					blockFont = style::font(font->size(), font->flags(), blockFont->family());
				}
			}
			if (flags & TextBlockFItalic) blockFont = blockFont->italic();
			if (flags & TextBlockFUnderline) blockFont = blockFont->underline();
			if (flags & TextBlockFTilde) { // tilde fix in OpenSans
				blockFont = st::semiboldFont;
			}
		}

		const auto part = str.mid(_from, length);

		// Attempt to catch a crash in text processing
		CrashReports::SetAnnotationRef("CrashString", &part);

		QStackTextEngine engine(part, blockFont->f);
		BlockParser parser(&engine, this, minResizeWidth, _from, part);

		CrashReports::ClearAnnotationRef("CrashString");
	}
}