示例#1
0
Paragraph Paragraph::rest(){
    Node_S * iterator = head->next;
    Paragraph p = Paragraph();
    while(iterator){
	p.append(iterator->data);
	iterator = iterator->next;
    }
    return p;
}
示例#2
0
void
MarkupParser::AppendMarkup(const TextDocumentRef& document, const BString& text)
{
	fTextDocument.SetTo(document);

	fCurrentCharacterStyle = &fNormalStyle;
	fCurrentParagraphStyle = &fParagraphStyle;

	fCurrentParagraph = Paragraph(*fCurrentParagraphStyle);
	fSpanStartOffset = 0;

	_ParseText(text);

	fTextDocument.Unset();
}
示例#3
0
文件: Xml4nlp.cpp 项目: PassStory/ltp
/////////////////////////////////////////////////////////////////////////////////////
/// build the paragraph structure in the DOM tree.
/// in the initial, a paragraph has only one sentence.
/////////////////////////////////////////////////////////////////////////////////////
int XML4NLP::BuildParagraph(string& strParagraph, int paragraphIdx) {

  TiXmlElement * documentPtr = document.documentPtr;
  vector<Paragraph> &paragraphs = document.paragraphs;

  paragraphs.push_back( Paragraph() );
  Paragraph &paragraph = paragraphs[paragraphs.size() - 1];

  paragraph.paragraphPtr = new TiXmlElement(TAG_PARA);
  paragraph.paragraphPtr->SetAttribute(TAG_ID, paragraphIdx);
  documentPtr->LinkEndChild(paragraph.paragraphPtr);

  TiXmlText *textPtr = new TiXmlText(strParagraph.c_str());
  paragraph.paragraphPtr->LinkEndChild( textPtr );

  return 0;
}
示例#4
0
文件: Xml4nlp.cpp 项目: PassStory/ltp
int XML4NLP::InitXmlParagraph(vector<Paragraph> &paragraphs, TiXmlElement *paragraphPtr)
{
  paragraphs.push_back( Paragraph() );
  Paragraph &paragraph = paragraphs[paragraphs.size()-1];
  paragraph.paragraphPtr = paragraphPtr;

  TiXmlElement *stnsPtr = paragraphPtr->FirstChildElement(TAG_SENT);
  if (stnsPtr == NULL) return 0;  // have not split sentence

  // record the sentence info
  do {
    if (0 != InitXmlSentence(paragraph.sentences, stnsPtr)) return -1;
    stnsPtr = stnsPtr->NextSiblingElement(TAG_SENT);
  } while(stnsPtr != NULL);

  return 0;
}
示例#5
0
PrintOut::PrintOut( QPrinter *printer )
    : pr( printer ), nextRule( NoRule ), page( 0 )
{
    p.begin( pr );
    QFont f( QLatin1String("Arial") );
    f8 = f;
    f8.setPointSize( 8 );
    f10 = f;
    f10.setPointSize( 10 );
    p.setFont( f10 );
    fmetrics = new QFontMetrics( p.fontMetrics() );
    hmargin = 5 * printer->width() / printer->widthMM(); // 5 mm
    vmargin = 5 * printer->height() / printer->heightMM(); // 5 mm
    hsize = printer->width() - 2 * hmargin;
    vsize = printer->height() - vmargin;
    dateTime = QDateTime::currentDateTime();
    breakPage(true); // init vsize and draw first header
    cp = Paragraph( QPoint(hmargin, voffset) );
}
示例#6
0
void PrintOut::flushLine(bool /* mayBreak */)
{
    if (voffset + cp.rect.height() > vsize)
        breakPage();
    else if (!firstParagraph)
        drawRule(nextRule);

    for (int i = 0; i < cp.boxes.count(); ++i) {
        Box b = cp.boxes[i];
        b.rect.translate(0, voffset);
        QRect r = b.rect;
        p.setFont(b.font);
        p.drawText(r, b.text, b.options);
    }
    voffset += cp.rect.height();

    nextRule = NoRule;
    cp = Paragraph(QPoint(hmargin, voffset));
    firstParagraph = false;
}
示例#7
0
void PrintOut::flushLine( bool /* mayBreak */ )
{
    if ( voffset + cp.rect.height() > vsize )
	breakPage();
    else if ( !firstParagraph )
	drawRule( nextRule );

    for ( int i = 0; i < (int) cp.boxes.count(); i++ ) {
	Box b = cp.boxes[i];
	b.rect.moveBy( 0, voffset );
	QRect r = b.rect;
	p.setFont( b.font );
	p.drawText( r, b.align, b.text );
    }
    voffset += cp.rect.height();

    nextRule = NoRule;
    cp = Paragraph( QPoint(hmargin, voffset) );
    firstParagraph = FALSE;
}
示例#8
0
PrintOut::PrintOut( QPrinter *printer )
    : pr( printer ), pdmetrics( printer ), nextRule( NoRule ), page( 0 )
{
    p.begin( pr );
    QFont f( "Arial" );
    f8 = f;
    f8.setPointSize( 8 );
    f10 = f;
    f10.setPointSize( 10 );
    p.setFont( f10 );
    fmetrics = new QFontMetrics( p.fontMetrics() );
    hmargin = 5 * pdmetrics.width() / pdmetrics.widthMM(); // 5 mm
    vmargin = 5 * pdmetrics.height() / pdmetrics.heightMM(); // 5 mm
    hsize = pdmetrics.width() - 2 * hmargin;
    vsize = pdmetrics.height() - vmargin;
    dateTime = QDateTime::currentDateTime();
    breakPage();
    vsize -= voffset;
    cp = Paragraph( QPoint(hmargin, voffset) );
}
示例#9
0
void LLConsole::update()
{
	{
		LLMutexLock lock(&mMutex);

		while (!mLines.empty())
		{
			mParagraphs.push_back(
				Paragraph(	mLines.front(), 
							LLColor4::white, 
							mTimer.getElapsedTimeF32(), 
							mFont, 
							(F32)getRect().getWidth()));
			mLines.pop_front();
		}
	}

	// remove old paragraphs which can't possibly be visible any more.  ::draw() will do something similar but more conservative - we do this here because ::draw() isn't guaranteed to ever be called!  (i.e. the console isn't visible)
	while ((S32)mParagraphs.size() > llmax((S32)0, (S32)(mMaxLines)))
	{
			mParagraphs.pop_front();
	}
}
示例#10
0
QList<QPair<QGithubMarkdown::Paragraph, QGithubMarkdown::List> > QGithubMarkdown::listize(const QList<QGithubMarkdown::Paragraph> &paragraphs)
{
	QList<QPair<Paragraph, List>> out;
	List currentList;

	auto finishList = [&]()
	{
		if (currentList.paragraphs.size() > 0)
		{
			out.append(qMakePair(Paragraph(), currentList));
		}
		currentList = List();
	};

	for (const Paragraph &paragraph : paragraphs)
	{
		if (paragraph.type != Paragraph::OrderedList && paragraph.type != Paragraph::UnorderedList)
		{
			finishList();
			out.append(qMakePair(paragraph, List()));
		}
		else
		{
			const int indent = (paragraph.indentTokens.size() / 2) + 1;
			if (currentList.indent != indent
					|| currentList.ordered != (paragraph.type == Paragraph::OrderedList))
			{
				finishList();
				currentList.indent = indent;
				currentList.ordered = (paragraph.type == Paragraph::OrderedList);
			}
			currentList.paragraphs.append(paragraph);
		}
	}
	return out;
}
示例#11
0
status_t
TextDocument::Insert(int32 textOffset, const BString& text,
	const CharacterStyle& characterStyle, const ParagraphStyle& paragraphStyle)
{
	int32 paragraphOffset;
	int32 index = ParagraphIndexFor(textOffset, paragraphOffset);
	if (index < 0)
		return B_BAD_VALUE;

	textOffset -= paragraphOffset;

	bool hasLineBreaks = text.FindFirst('\n', 0) >= 0;

	if (hasLineBreaks) {
		// Split paragraph at textOffset
		Paragraph paragraph1(ParagraphAt(index).Style());
		Paragraph paragraph2(paragraphStyle);
		const TextSpanList& textSpans = ParagraphAt(index).TextSpans();
		int32 spanCount = textSpans.CountItems();
		for (int32 i = 0; i < spanCount; i++) {
			const TextSpan& span = textSpans.ItemAtFast(i);
			int32 spanLength = span.CountChars();
			if (textOffset >= spanLength) {
				paragraph1.Append(span);
				textOffset -= spanLength;
			} else if (textOffset > 0) {
				paragraph1.Append(
					span.SubSpan(0, textOffset));
				paragraph2.Append(
					span.SubSpan(textOffset, spanLength - textOffset));
				textOffset = 0;
			} else {
				paragraph2.Append(span);
			}
		}

		fParagraphs.Remove(index);

		// Insert TextSpans, splitting 'text' into Paragraphs at line breaks.
		int32 length = text.CountChars();
		int32 chunkStart = 0;
		while (chunkStart < length) {
			int32 chunkEnd = text.FindFirst('\n', chunkStart);
			bool foundLineBreak = chunkEnd >= chunkStart;
			if (foundLineBreak)
				chunkEnd++;
			else
				chunkEnd = length;

			BString chunk;
			text.CopyCharsInto(chunk, chunkStart, chunkEnd - chunkStart);
			TextSpan span(chunk, characterStyle);

			if (foundLineBreak) {
				if (!paragraph1.Append(span))
					return B_NO_MEMORY;
				if (paragraph1.Length() > 0) {
					if (!fParagraphs.Add(paragraph1, index))
						return B_NO_MEMORY;
					index++;
				}
				paragraph1 = Paragraph(paragraphStyle);
			} else {
				if (!paragraph2.Prepend(span))
					return B_NO_MEMORY;
			}

			chunkStart = chunkEnd + 1;
		}

		if (paragraph2.IsEmpty()) {
			// Make sure Paragraph has at least one TextSpan, even
			// if its empty.
			const TextSpanList& spans = paragraph1.TextSpans();
			const TextSpan& span = spans.LastItem();
			paragraph2.Append(TextSpan("", span.Style()));
		}

		if (!fParagraphs.Add(paragraph2, index))
			return B_NO_MEMORY;
	} else {
		Paragraph paragraph(ParagraphAt(index));
		paragraph.Insert(textOffset, TextSpan(text, characterStyle));
		if (!fParagraphs.Replace(index, paragraph))
			return B_NO_MEMORY;
	}

	return B_OK;
}
示例#12
0
QList<QGithubMarkdown::Paragraph> QGithubMarkdown::paragraphize(const QList<QGithubMarkdown::Token> &tokens)
{
	QList<Paragraph> out;
	Paragraph currentParagraph;
	QListIterator<Token> iterator(tokens);

	auto peekPreviousInternal = [&]() { return iterator.hasPrevious() ? iterator.peekPrevious() : Token(); };
	auto peekPrevious = [&]()
	{
		const Token previous = peekPreviousInternal();
		if (previous.type == Token::Invalid)
		{
			return Token();
		}
		iterator.previous();
		const Token ret = peekPreviousInternal();
		iterator.next(); // don't forget to undo the call to next
		return ret;
	};
	auto firstNonSpaceOnLine = [&]()
	{
		int numTokens = 0;
		while (peekPrevious().type == Token::Character && peekPrevious().content.toString() == " ")
		{
			numTokens++;
			iterator.previous();
		}
		bool ret = peekPrevious().type == Token::Invalid || peekPrevious().type == Token::NewLine;
		// roll back
		while (numTokens > 0)
		{
			numTokens--;
			iterator.next();
		}
		return ret;
	};
	auto nextParagraph = [&]()
	{
		if (!currentParagraph.tokens.isEmpty())
		{
			if ((currentParagraph.tokens.last().type == Token::Character
					&& currentParagraph.tokens.last().source == "\n")
					|| currentParagraph.tokens.last().type == Token::NewLine)
			{
				currentParagraph.tokens.removeLast();
			}
			if (!currentParagraph.tokens.isEmpty())
			{
				out.append(currentParagraph);
			}
		}
		currentParagraph = Paragraph();
	};

	QList<Token> spaceTokens;

	while (iterator.hasNext())
	{
		const Token token = iterator.next();
		const bool isFirstNonSpace = firstNonSpaceOnLine();

		if (token.type == Token::EOD)
		{
			break;
		}
		if (isFirstNonSpace && token.type == Token::Character && token.content == ' ')
		{
			spaceTokens += token;
			continue;
		}
		if (token.type == Token::NewLine)
		{
			spaceTokens.clear();
		}

		if (token.type == Token::NewLine && peekPrevious().type == Token::NewLine)
		{
			nextParagraph();
		}
		else if (token.type == Token::CodeDelimiter)
		{
			currentParagraph.type = Paragraph::Code;
			while (iterator.hasNext() && iterator.peekNext().type != Token::CodeDelimiter)
			{
				currentParagraph.tokens.append(iterator.next());
			}
			if (iterator.hasNext())
			{
				iterator.next(); // consume code end delimiter
			}
			nextParagraph();
		}
		else if (token.type == Token::QuoteStart && isFirstNonSpace)
		{
			currentParagraph.type = Paragraph::Quote;
		}
		else if (token.type == Token::HeadingStart && isFirstNonSpace)
		{
			currentParagraph.type = (Paragraph::Type)token.content.toInt();
		}
		else if (token.type == Token::UnorderedListStart && isFirstNonSpace)
		{
			nextParagraph();
			currentParagraph.type = Paragraph::UnorderedList;
			currentParagraph.indentTokens = spaceTokens;
		}
		else if (token.type == Token::OrderedListStart && isFirstNonSpace)
		{
			nextParagraph();
			currentParagraph.type = Paragraph::OrderedList;
			currentParagraph.indentTokens = spaceTokens;
		}
		else if (token.type == Token::NewLine)
		{
			Token token;
			token.type = Token::Character;
			token.source = '\n';
			token.content = QChar(' ');
			currentParagraph.tokens += token;
		}
		else
		{
			currentParagraph.tokens += token;
		}
	}

	if (!currentParagraph.tokens.isEmpty())
	{
		out.append(currentParagraph);
	}

	return out;
}
示例#13
0
RTFStatus RTFReader::ParseDocument(RTFToken p_token, int4 p_value)
{
	RTFStatus t_status;
	t_status = kRTFStatusSuccess;

	RTFToken t_token;
	t_token = p_token & kRTFTokenMask;

	bool t_has_parameter;
	t_has_parameter = (p_token & kRTFTokenHasParameter) != 0;

	switch(t_token)
	{
	case kRTFTokenSkipDestination:
		m_state . SetDestination(kRTFDestinationSkip);
	break;
	
	case kRTFTokenFontTable:
		m_state . SetDestination(kRTFDestinationFontTable);
	break;
	
	case kRTFTokenColorTable:
		m_state . SetDestination(kRTFDestinationColorTable);
	break;
	
	case kRTFTokenListTable:
		m_state . SetDestination(kRTFDestinationListTable);
	break;

	case kRTFTokenListText:
		m_list_skip = true;
		m_state . SetDestination(kRTFDestinationListText);
	break;
			
	case kRTFTokenListOverrideTable:
		m_state . SetDestination(kRTFDestinationListOverrideTable);
	break;

	case kRTFTokenFldInst:
		m_state . SetDestination(kRTFDestinationFldInst);
	break;

	case kRTFTokenField:
	break;
			
	case kRTFTokenDefaultFont:
		if (t_has_parameter)
			m_default_font = p_value;
	break;

	case kRTFTokenAnsi:
		m_default_text_encoding = kMCTextEncodingWindows1252;
	break;

	case kRTFTokenMac:
		m_default_text_encoding = kMCTextEncodingMacRoman;
	break;

	case kRTFTokenPC:
		m_default_text_encoding = (MCTextEncoding)(kMCTextEncodingWindowsNative + 437);
	break;

	case kRTFTokenPCA:
		m_default_text_encoding = (MCTextEncoding)(kMCTextEncodingWindowsNative + 850);
	break;

	case kRTFTokenAnsiCodepage:
		if (t_has_parameter)
		{
			if (p_value < 0)
				p_value = 65536 + p_value;
			
			m_default_text_encoding = (MCTextEncoding)(kMCTextEncodingWindowsNative + p_value);
		}
	break;

	case kRTFTokenUnicodeSkip:
		if (t_has_parameter)
			m_state . SetUnicodeSkip(p_value);
	break;

	case kRTFTokenNewLine:
	case kRTFTokenParagraph:
		t_status = Flush(true);
		if (t_status == kRTFStatusSuccess)
		{
			if (m_needs_paragraph)
				Paragraph();
			m_needs_paragraph = true;
		}
	break;

	case kRTFTokenResetParagraphStyle:
		// MW-2012-03-14: [[ RtfParaStyles ]] Reset all the paragraph styles to defaults.
		m_state . SetListStyle(kMCTextListStyleNone);
		m_state . SetListLevel(0);
		m_state . SetListIndex(0);
		m_state . SetBorderWidth(0);
		m_state . SetPadding(0);
		m_state . SetFirstIndent(0);
		m_state . SetLeftIndent(0);
		m_state . SetRightIndent(0);
		m_state . SetSpaceAbove(0);
		m_state . SetSpaceBelow(0);
		m_state . SetParagraphBackgroundColor(0xffffffff);
		m_state . SetBorderColor(0xffffffff);
			
		// MW-2014-01-08: [[ Bug 11627 ]] Make sure the text alignment attribute is reset.
		m_state . SetTextAlign(kMCTextTextAlignLeft);
		break;

	case kRTFTokenRow:
		m_table_cell = false;

		t_status = Flush(true);
		if (t_status == kRTFStatusSuccess)
		{
			if (m_needs_paragraph)
				Paragraph();
			m_needs_paragraph = true;
		}
	break;

	case kRTFTokenCell:
		if (m_table_cell)
		{
			m_table_cell = false;
			t_status = m_text . Output(9, kMCTextEncodingUTF16);
		}
		if (t_status == kRTFStatusSuccess && m_attributes_changed)
			t_status = Flush();
		if (t_status == kRTFStatusSuccess)
			m_table_cell = true;
	break;

	case kRTFTokenColor:
		if (t_has_parameter)
		{
			m_state .  SetForegroundColor(m_colors . Get(p_value));
			m_attributes_changed = true;
		}
	break;

	case kRTFTokenHighlight:
		if (t_has_parameter)
		{
			m_state . SetBackgroundColor(m_colors . Get(p_value));
			m_attributes_changed = true;
		}
	break;

	case kRTFTokenPlain:
		m_state . SetFontName(NULL);
		m_state . SetFontStyle(kRTFFontStyleNone);
		m_state . SetFontSize(0);
		m_attributes_changed = true;
	break;

	case kRTFTokenFont:
		if (t_has_parameter)
		{
			static struct { int charset; MCTextEncoding encoding; } s_charset_mapping[] =
			{
				{ ANSI_CHARSET, kMCTextEncodingWindows1252 },
				{ SYMBOL_CHARSET, kMCTextEncodingSymbol },
				{ MAC_CHARSET , kMCTextEncodingMacRoman },
				{ SHIFTJIS_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 932) },
				{ HANGEUL_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 949) },
				{ JOHAB_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 1361) },
				{ GB2312_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 936) },
				{ CHINESEBIG5_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 950) },
				{ GREEK_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 1253) },
				{ TURKISH_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 1254) },
				{ VIETNAMESE_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 1258) },
				{ HEBREW_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 1255) },
				{ ARABIC_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 1256) },
				{ BALTIC_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 1257) },
				{ RUSSIAN_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 1251) },
				{ THAI_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 874) },
				{ EASTEUROPE_CHARSET, MCTextEncoding(kMCTextEncodingWindowsNative + 1250) },
				{ /* PC437_CHARSET */ 254, MCTextEncoding(kMCTextEncodingWindowsNative + 437) },
				{ -1, kMCTextEncodingUndefined }
			};

			const char *t_new_font;
			t_new_font = m_fonts . GetName(p_value);

			uint4 t_new_charset;
			t_new_charset = m_fonts . GetCharset(p_value);

			MCTextEncoding t_new_encoding;
			if (t_new_charset == DEFAULT_CHARSET)
				t_new_encoding = m_default_text_encoding;
			else
			{
				uint4 t_charset_index;
				for(t_charset_index = 0; s_charset_mapping[t_charset_index] . charset != -1; ++t_charset_index)
					if (s_charset_mapping[t_charset_index] . charset == t_new_charset)
						break;
				t_new_encoding = s_charset_mapping[t_charset_index] . encoding;
			}

			m_state . SetTextEncoding(t_new_encoding);
			m_state . SetFontName(t_new_font);
			m_attributes_changed = true;
		}
	break;

	case kRTFTokenFontSize:
		if (t_has_parameter)
		{
			m_state . SetFontSize(p_value);
			m_attributes_changed = true;
		}
	break;

	case kRTFTokenBold:
	case kRTFTokenItalic:
	case kRTFTokenUnderline:
	case kRTFTokenNoUnderline:
	case kRTFTokenStrikethrough:
	case kRTFTokenSuperscript:
	case kRTFTokenSubscript:
	{
		bool t_turn_off;
		t_turn_off = t_has_parameter && p_value == 0;

		RTFFontStyle t_mask;
		if (t_token == kRTFTokenBold)
			t_mask = kRTFFontStyleBold;
		else if (t_token == kRTFTokenItalic)
			t_mask = kRTFFontStyleItalic;
		else if (t_token == kRTFTokenUnderline)
			t_mask = kRTFFontStyleUnderline;
		else if (t_token == kRTFTokenNoUnderline)
		{
			t_mask = kRTFFontStyleUnderline;
			t_turn_off = true;
		}
		else if (t_token == kRTFTokenStrikethrough)
			t_mask = kRTFFontStyleStrikethrough;
		else if (t_token == kRTFTokenSuperscript)
			t_mask = kRTFFontStyleSuperscript;
		else if (t_token == kRTFTokenSubscript)
			t_mask = kRTFFontStyleSubscript;

		RTFFontStyle t_new_style;
		if (t_turn_off)
			t_new_style = m_state . GetFontStyle() & ~t_mask;
		else
			t_new_style = m_state . GetFontStyle() | t_mask;

		m_state . SetFontStyle(t_new_style);
		m_attributes_changed = true;
	}
	break;

	case kRTFTokenTab:
		if (t_status == kRTFStatusSuccess && m_table_cell)
		{
			m_table_cell = false;
			t_status = m_text . Output(9, kMCTextEncodingUTF16);
		}
		if (m_attributes_changed)
			t_status = Flush();
		if (t_status == kRTFStatusSuccess)
			t_status = m_text . Output(9, kMCTextEncodingUTF16);
	break;

	case kRTFTokenUnicode:
	{
		if (t_has_parameter)
		{
			if (t_status == kRTFStatusSuccess && m_table_cell)
			{
				m_table_cell = false;
				t_status = m_text . Output(9, kMCTextEncodingUTF16);
			}
			if (m_attributes_changed)
				t_status = Flush();
			if (t_status == kRTFStatusSuccess)
				t_status = m_text . Output(p_value & 0xFFFF, kMCTextEncodingUTF16);
			if (t_status == kRTFStatusSuccess)
				m_input_skip_count = m_state . GetUnicodeSkip();
		}
	}
	break;

	case kRTFTokenCharacter:
	{
		MCTextEncoding t_encoding;
		t_encoding = m_state . GetTextEncoding();
		if (t_encoding == kMCTextEncodingUndefined)
			t_encoding = m_default_text_encoding;
		if (t_status == kRTFStatusSuccess && m_table_cell)
		{
			m_table_cell = false;
			t_status = m_text . Output(9, kMCTextEncodingUTF16);
		}
		if (m_attributes_changed)
			t_status = Flush();
		if (t_status == kRTFStatusSuccess)
			t_status = m_text . Output(p_value, t_encoding);
	}
	break;

	// MW-2010-01-08: [[ Bug 8143 ]] Make sure we handle special chars and map then to UTF-16
	case kRTFTokenBullet:
		t_status = m_text . Output(0x2022, kMCTextEncodingUTF16);
		break;
	case kRTFTokenLeftQuote:
		t_status = m_text . Output(0x2018, kMCTextEncodingUTF16);
		break;
	case kRTFTokenRightQuote:
		t_status = m_text . Output(0x2019, kMCTextEncodingUTF16);
		break;
	case kRTFTokenLeftDoubleQuote:
		t_status = m_text . Output(0x201C, kMCTextEncodingUTF16);
		break;
	case kRTFTokenRightDoubleQuote:
		t_status = m_text . Output(0x201D, kMCTextEncodingUTF16);
		break;
			
	// Handle the 'listselect' style lists.
	case kRTFTokenListSelect:
		if (t_has_parameter)
			m_state . SetListIndex(p_value);
	break;

	// MW-2012-03-14: [[ RtfParaStyles ]] Handle the list level select.
	case kRTFTokenListSelectLevel:
		if (t_has_parameter && p_value >= 0 && p_value <= 8)
			m_state . SetListLevel(p_value);
		break;

	// MW-2012-03-14: [[ RtfParaStyles ]] Handle all the paragraph style tags.
	case kRTFTokenParagraphBackgroundColor:
		if (t_has_parameter)
			m_state . SetParagraphBackgroundColor(m_colors . Get(p_value));
		break;
	case kRTFTokenParagraphBorderWidth:
		if (t_has_parameter)
			m_state . SetBorderWidth(p_value);
		break;
	case kRTFTokenParagraphBorderColor:
		if (t_has_parameter)
			m_state . SetBorderColor(m_colors . Get(p_value));
		break;
	case kRTFTokenParagraphPadding:
		if (t_has_parameter)
			m_state . SetPadding(p_value);
		break;
	case kRTFTokenLeftIndent:
		if (t_has_parameter)
			m_state . SetLeftIndent(p_value);
		break;
	case kRTFTokenRightIndent:
		if (t_has_parameter)
			m_state . SetRightIndent(p_value);
		break;
	case kRTFTokenFirstIndent:
		if (t_has_parameter)
			m_state . SetFirstIndent(p_value);
		break;
	case kRTFTokenSpaceAbove:
		if (t_has_parameter)
			m_state . SetSpaceAbove(p_value);
		break;
	case kRTFTokenSpaceBelow:
		if (t_has_parameter)
			m_state . SetSpaceBelow(p_value);
		break;
	case kRTFTokenLeftJustify:
		m_state . SetTextAlign(kMCTextTextAlignLeft);
		break;
	case kRTFTokenRightJustify:
		m_state . SetTextAlign(kMCTextTextAlignRight);
		break;
	case kRTFTokenCenterJustify:
		m_state . SetTextAlign(kMCTextTextAlignCenter);
		break;
	}
	
	return t_status;
}
示例#14
0
RTFStatus RTFReader::Flush(bool p_force)
{
	RTFStatus t_status;
	t_status = kRTFStatusSuccess;

	if (!m_attributes_changed && !p_force)
		return t_status;

	MCTextBlock t_block;
	bool t_changed;
	t_changed = false;
	if (m_attributes_changed)
	{
		t_block . foreground_color = m_state . GetForegroundColor();
		t_block . background_color = m_state . GetBackgroundColor();
		t_block . font_name = m_state . GetFontName();
		if (m_state . GetFontSize() != 0)
			t_block . font_size = half_points_to_pixels(m_state . GetFontSize());
		else
			t_block . font_size = 0;
		
		t_block . font_style = FA_DEFAULT_STYLE;
		if ((m_state . GetFontStyle() & kRTFFontStyleItalic) != 0)
			t_block . font_style |= FA_ITALIC;
		if ((m_state . GetFontStyle() & kRTFFontStyleBold) != 0)
			t_block . font_style |= FA_BOLD;
		if ((m_state . GetFontStyle() & kRTFFontStyleUnderline) != 0)
			t_block . font_style |= FA_UNDERLINE;
		if ((m_state . GetFontStyle() & kRTFFontStyleStrikethrough) != 0)
			t_block . font_style |= FA_STRIKEOUT;
		if ((m_state . GetFontStyle() & kRTFFontStyleLink) != 0)
			t_block . font_style |= FA_LINK;

		if ((m_state . GetFontStyle() & kRTFFontStyleSuperscript) != 0)
			t_block . text_shift = -4;
		else if ((m_state . GetFontStyle() & kRTFFontStyleSubscript) != 0)
			t_block . text_shift = 4;
		else
			t_block . text_shift = 0;
		
		if (m_state . GetHyperlink() != kMCEmptyName)
			MCNameClone(m_state . GetHyperlink(), t_block . text_link);
		else
			t_block . text_link = nil;

		if (m_state . GetMetadata() != kMCEmptyName)
			MCNameClone(m_state . GetMetadata(), t_block . text_metadata);
		else
			t_block . text_metadata = nil;

		t_block . string_native = false;
		t_block . string_buffer = NULL;
		t_block . string_length = 0;

		if (t_block . foreground_color != m_attributes . foreground_color ||
			t_block . background_color != m_attributes . background_color ||
			t_block . font_size != m_attributes . font_size ||
			t_block . font_style != m_attributes . font_style ||
			t_block . text_shift != m_attributes . text_shift ||
			CStringCompare(t_block . font_name, m_attributes . font_name) != 0 ||
			t_block . text_link != m_attributes . text_link ||
			t_block . text_metadata != m_attributes . text_metadata)
			t_changed = true;
	}

	const uint2 *t_string_buffer;
	uint4 t_string_length;
	if (t_status == kRTFStatusSuccess)
		t_status = m_text . Borrow(t_string_buffer, t_string_length);

	if (t_status == kRTFStatusSuccess && t_string_length > 0 && (t_changed || p_force))
	{
		if (m_needs_paragraph)
		{
			m_needs_paragraph = false;

			// MW-2012-03-14: [[ RtfParaStyles ]] Use the 'Paragraph()' method to ensure
			//   paragraph styles get applied.
			Paragraph();
		}

		m_attributes . string_native = false;
		m_attributes . string_buffer = t_string_buffer;
		m_attributes . string_length = t_string_length / 2;
		m_converter(m_converter_context, NULL, &m_attributes);
		m_text . Clear();
	}

	if (t_changed)
	{
		MCNameDelete(m_attributes . text_metadata);
		MCNameDelete(m_attributes . text_link);
		memcpy(&m_attributes, &t_block, sizeof(MCTextBlock));
		m_attributes_changed = false;
	}

	return t_status;
}
示例#15
0
/*
** Break markup is any kind of markup that might force a line-break. This
** routine handles a single element of break markup and returns a pointer
** to the first element past that markup.  If p doesn't point to break
** markup, then p is returned.  If p is an incomplete table (a <TABLE>
** that lacks a </TABLE>), then NULL is returned.
*/
static HtmlElement *DoBreakMarkup(
  HtmlLayoutContext *pLC,
  HtmlElement *p
){
  HtmlElement *pNext = p->pNext;
  char *z;
  int x, y, w;

  switch( p->base.type ){
    case Html_A:
      p->anchor.y = pLC->bottom;
      TestPoint(0);
      break;

    case Html_BLOCKQUOTE:
      HtmlPushMargin(&pLC->leftMargin, HTML_INDENT, -1, Html_EndBLOCKQUOTE);
      HtmlPushMargin(&pLC->rightMargin, HTML_INDENT, -1, Html_EndBLOCKQUOTE);
      Paragraph(pLC, p);
      TestPoint(0);
      break;
    case Html_EndBLOCKQUOTE:
      HtmlPopMargin(&pLC->leftMargin, Html_EndBLOCKQUOTE, pLC);
      HtmlPopMargin(&pLC->rightMargin, Html_EndBLOCKQUOTE, pLC);
      Paragraph(pLC, p);
      TestPoint(0);
      break;

    case Html_IMG:
      switch( p->image.align ){
        case IMAGE_ALIGN_Left:
          HtmlComputeMargins(pLC, &x, &y, &w);
          p->image.x = x;
          p->image.y = y;
          p->image.ascent = 0;
          p->image.descent = p->image.h;
          HtmlPushMargin(&pLC->leftMargin, p->image.w + 2, y + p->image.h, 0);
          SETMAX( pLC->maxY, y + p->image.h );
          SETMAX( pLC->maxX, x + p->image.w );
          break;
        case IMAGE_ALIGN_Right:
          HtmlComputeMargins(pLC, &x, &y, &w);
          p->image.x = x + w - p->image.w;
          p->image.y = y;
          p->image.ascent = 0;
          p->image.descent = p->image.h;
          HtmlPushMargin(&pLC->rightMargin, p->image.w + 2, y + p->image.h, 0);
          SETMAX( pLC->maxY, y + p->image.h );
          SETMAX( pLC->maxX, x + p->image.w );
          break;
        default:
          TestPoint(0);
          pNext = p;
          break;
      }
      break;

    
    case Html_PRE:
      /* Skip space tokens thru the next newline. */
      while( pNext->base.type==Html_Space ){
        HtmlElement *pThis = pNext;
        pNext = pNext->pNext;
        if( pThis->base.flags & HTML_NewLine ){ TestPoint(0); break; }
      }
      Paragraph(pLC,p);
      break;

    case Html_UL:
    case Html_MENU:
    case Html_DIR:
    case Html_OL:
      if( p->list.compact==0 ){
        Paragraph(pLC,p);
      }
      HtmlPushMargin(&pLC->leftMargin, HTML_INDENT, -1, p->base.type+1);
      break;

    case Html_EndOL:
    case Html_EndUL:
    case Html_EndMENU:
    case Html_EndDIR:
      if( p->ref.pOther ){
        HtmlPopMargin(&pLC->leftMargin, p->base.type, pLC);
        if( !p->ref.pOther->list.compact ){
          Paragraph(pLC,p);
        }
      }
      break;

    case Html_DL:
      Paragraph(pLC,p);
      HtmlPushMargin(&pLC->leftMargin, HTML_INDENT, -1, Html_EndDL);
      TestPoint(0);
      break;

    case Html_EndDL:
      HtmlPopMargin(&pLC->leftMargin, Html_EndDL, pLC);
      Paragraph(pLC,p);
      TestPoint(0);
      break;

    case Html_HR: {
      int zl, wd;

      p->hr.is3D = HtmlMarkupArg(p, "noshade", 0)==0;
      z = HtmlMarkupArg(p, "size", 0);
      if( z ){
        p->hr.h = atoi(z);
      }else{
        p->hr.h = 0;
      }
      if( p->hr.h<1 ){
        int relief = pLC->htmlPtr->ruleRelief;
        if( p->hr.is3D 
        && (relief==TK_RELIEF_SUNKEN || relief==TK_RELIEF_RAISED) ){
          p->hr.h = 3;
        }else{
          p->hr.h = 2;
        }
      }
      HtmlComputeMargins(pLC, &x, &y, &w);
      p->hr.y = y;
      y += p->hr.h + 1;
      p->hr.x = x;
      z = HtmlMarkupArg(p, "width", "100%");
      zl = strlen(z);
      if( zl>0 && z[zl-1]=='%' ){
        wd = (atoi(z)*w)/100;
      }else{
        wd = atoi(z);
      }
      if( wd>w ) wd = w;
      p->hr.w = wd;
      switch( p->base.style.align ){
        case ALIGN_Center:
        case ALIGN_None:
          p->hr.x += (w - wd)/2;
          TestPoint(0);
          break;
        case ALIGN_Right:
          p->hr.x += (w - wd);
          TestPoint(0);
          break;
        default:
          TestPoint(0);
          break;
      }
      SETMAX( pLC->maxY, y);
      SETMAX( pLC->maxX, wd + p->hr.x );
      pLC->bottom = y;
      pLC->headRoom = 0;
      break;
    }

    case Html_ADDRESS:
    case Html_EndADDRESS:
    case Html_CENTER:
    case Html_EndCENTER:
    case Html_DIV:
    case Html_EndDIV:
    case Html_H1:
    case Html_EndH1:
    case Html_H2:
    case Html_EndH2:
    case Html_H3:
    case Html_EndH3:
    case Html_H4:
    case Html_EndH4:
    case Html_H5:
    case Html_EndH5:
    case Html_H6:
    case Html_EndH6:
    case Html_P:
    case Html_EndP:
    case Html_EndPRE:
      Paragraph(pLC, p);
      TestPoint(0);
      break;

    case Html_TABLE:
      pNext = HtmlTableLayout(pLC, p);
      TestPoint(0);
      break;

    case Html_BR:
      z = HtmlMarkupArg(p, "clear",0);
      if( z ){
        if( stricmp(z,"left")==0 ){
          ClearObstacle(pLC, CLEAR_Left);
          TestPoint(0);
        }else if( stricmp(z,"right")==0 ){
          ClearObstacle(pLC, CLEAR_Right);
          TestPoint(0);
        }else{
          ClearObstacle(pLC, CLEAR_Both);
          TestPoint(0);
        }
      }else{
        TestPoint(0);
      }
      break;

    /* All of the following tags need to be handed to the GetLine() routine */
    case Html_Text:
    case Html_Space:
    case Html_LI:
    case Html_INPUT:
    case Html_SELECT:
    case Html_TEXTAREA:
    case Html_APPLET:
    case Html_EMBED:
      pNext = p;
      TestPoint(0);
      break;

    default:
      TestPoint(0);
      break;
  }
  return pNext;
}