void RichQtfParser::Flush() { if(text.GetLength()) { ASSERT(!istable); paragraph.Cat(text, format); text.Clear(); } }
void RichQtfParser::EndPart() { if(istable) { if(paragraph.GetCount() == 0 && text.GetCount() == 0) if(table.GetCount()) table.Top().text.CatPick(pick(tablepart)); else target.CatPick(pick(tablepart)); else { paragraph.part.Clear(); text.Clear(); } } else { Flush(); bool b = paragraph.format.newpage; if(breakpage) paragraph.format.newpage = true; if(table.GetCount()) table.Top().text.Cat(paragraph, target.GetStyles()); else target.Cat(paragraph); paragraph.part.Clear();; paragraph.format.newpage = b; SetFormat(); breakpage = false; } istable = false; }
// Generates a line of text rendered from this element bool ElementTextDefault::GenerateLine(WString& line, int& line_length, float& line_width, int line_begin, float maximum_line_width, float right_spacing_width, bool trim_whitespace_prefix) { FontFaceHandle* font_face_handle = GetFontFaceHandle(); // Initialise the output variables. line.Clear(); line_length = 0; line_width = 0; // Bail if we don't have a valid font face. if (font_face_handle == NULL) return true; // Determine how we are processing white-space while formatting the text. int white_space_property = GetProperty< int >(WHITE_SPACE); bool collapse_white_space = white_space_property == WHITE_SPACE_NORMAL || white_space_property == WHITE_SPACE_NOWRAP || white_space_property == WHITE_SPACE_PRE_LINE; bool break_at_line = maximum_line_width >= 0 && (white_space_property == WHITE_SPACE_NORMAL || white_space_property == WHITE_SPACE_PRE_WRAP || white_space_property == WHITE_SPACE_PRE_LINE); bool break_at_endline = white_space_property == WHITE_SPACE_PRE || white_space_property == WHITE_SPACE_PRE_WRAP || white_space_property == WHITE_SPACE_PRE_LINE; // Determine what (if any) text transformation we are putting the characters through. int text_transform_property = GetProperty< int >(TEXT_TRANSFORM); // Starting at the line_begin character, we generate sections of the text (we'll call them tokens) depending on the // white-space parsing parameters. Each section is then appended to the line if it can fit. If not, or if an // endline is found (and we're processing them), then the line is ended. kthxbai! const word* token_begin = text.CString() + line_begin; const word* string_end = text.CString() + text.Length(); while (token_begin != string_end) { WString token; const word* next_token_begin = token_begin; // Generate the next token and determine its pixel-length. bool break_line = BuildToken(token, next_token_begin, string_end, line.Empty() && trim_whitespace_prefix, collapse_white_space, break_at_endline, text_transform_property); int token_width = font_face_handle->GetStringWidth(token, line.Empty() ? 0 : line[line.Length() - 1]); // If we're breaking to fit a line box, check if the token can fit on the line before we add it. if (break_at_line) { if (!line.Empty() && (line_width + token_width > maximum_line_width || LastToken(next_token_begin, string_end, collapse_white_space, break_at_endline) && line_width + token_width > maximum_line_width - right_spacing_width)) { return false; } } // The token can fit on the end of the line, so add it onto the end and increment our width and length // counters. line += token; line_length += (next_token_begin - token_begin); line_width += token_width; // Break out of the loop if an endline was forced. if (break_line) return false; // Set the beginning of the next token. token_begin = next_token_begin; } return true; }