void XtgScanner::defAtRate() { enterState(nameMode); sfcName = getToken(); if (sfcName == "@$:") { if (doc->paragraphStyles().contains(m_item->itemName() + "_Normal")) { ParagraphStyle newStyle; newStyle.setParent(m_item->itemName() + "_Normal"); currentParagraphStyle = newStyle; currentCharStyle = newStyle.charStyle(); } else if (doc->paragraphStyles().contains("Normal")) { ParagraphStyle newStyle; newStyle.setParent("Normal"); currentParagraphStyle = newStyle; currentCharStyle = newStyle.charStyle(); } enterState(previousState()); } else if (sfcName == "@:") { QString pStyle = CommonStrings::DefaultParagraphStyle; ParagraphStyle newStyle; newStyle.setParent(pStyle); newStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing); currentParagraphStyle = newStyle; currentCharStyle = newStyle.charStyle(); currentCharStyle.setFontSize(120.0); styleEffects = ScStyle_None; currentCharStyle.setFeatures(styleEffects.featureList()); enterState(textMode); } else if (doc->paragraphStyles().contains(m_item->itemName() + "_" + sfcName)) { ParagraphStyle newStyle; newStyle.setParent(m_item->itemName() + "_" + sfcName); currentParagraphStyle = newStyle; currentCharStyle = newStyle.charStyle(); if (lookAhead() == ':') top++; enterState(textMode); } else if (doc->paragraphStyles().contains(sfcName)) { ParagraphStyle newStyle; newStyle.setParent(sfcName); currentParagraphStyle = newStyle; currentCharStyle = newStyle.charStyle(); if (lookAhead() == ':') top++; enterState(textMode); } }
void XtgScanner::defColon() { flushText(); if ((sfcName == "@") || (sfcName == "@$:") || (sfcName == "@:")) { QString pStyle = CommonStrings::DefaultParagraphStyle; ParagraphStyle newStyle; newStyle.setParent(pStyle); newStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing); currentParagraphStyle = newStyle; currentCharStyle = newStyle.charStyle(); currentCharStyle.setFontSize(120.0); styleEffects = ScStyle_None; currentCharStyle.setFeatures(styleEffects.featureList()); } else if (doc->paragraphStyles().contains(m_item->itemName() + "_" + sfcName)) { ParagraphStyle newStyle; newStyle.setParent(m_item->itemName() + "_" + sfcName); currentParagraphStyle = newStyle; currentCharStyle = newStyle.charStyle(); } else if (doc->paragraphStyles().contains(sfcName)) { ParagraphStyle newStyle; newStyle.setParent(sfcName); currentParagraphStyle = newStyle; currentCharStyle = newStyle.charStyle(); } else { QString pStyle = CommonStrings::DefaultParagraphStyle; ParagraphStyle newStyle; newStyle.setParent(pStyle); newStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing); currentParagraphStyle = newStyle; currentCharStyle = newStyle.charStyle(); currentCharStyle.setFontSize(120.0); styleEffects = ScStyle_None; currentCharStyle.setFeatures(styleEffects.featureList()); } if (newlineFlag) { int posT = m_item->itemText.length(); if (posT > 0) { m_item->itemText.insertChars(posT, SpecialChars::PARSEP); m_item->itemText.applyStyle(posT, currentParagraphStyle); } } newlineFlag = false; enterState(textMode); define = 0; if (!((lookAhead() == '\r') || (lookAhead() == '\n'))) inDef = false; }
PageItem_NoteFrame::PageItem_NoteFrame(NotesStyle *nStyle, ScribusDoc *doc, double x, double y, double w, double h, double w2, QString fill, QString outline) : PageItem_TextFrame(doc, x, y, w, h, w2, fill, outline) { m_nstyle = nStyle; m_masterFrame = NULL; itemText.clear(); AnName = generateUniqueCopyName(nStyle->isEndNotes() ? tr("Endnote frame ") + m_nstyle->name() : tr("Footnote frame ") + m_nstyle->name(), false); AutoName = false; //endnotes frame will saved with name setUName(AnName); //set default style for note frame ParagraphStyle newStyle; if (nStyle->notesParStyle().isEmpty() || (nStyle->notesParStyle() == tr("No Style"))) { if (nStyle->isEndNotes()) //set default doc style newStyle.setParent(m_Doc->paragraphStyles()[0].name()); else { newStyle.setParent(m_masterFrame->itemText.defaultStyle().parent()); newStyle.applyStyle(m_masterFrame->currentStyle()); } } else newStyle.setParent(nStyle->notesParStyle()); itemText.blockSignals(true); itemText.setDefaultStyle(newStyle); itemText.blockSignals(false); textFlowModeVal = TextFlowUsesFrameShape; setColumns(1); if (m_nstyle->isAutoNotesHeight()) m_SizeVLocked = true; else m_SizeVLocked = false; if (m_nstyle->isAutoNotesWidth()) m_SizeHLocked = true; else m_SizeHLocked = false; if (m_nstyle->isAutoNotesHeight() && m_nstyle->isAutoNotesWidth()) m_SizeLocked = true; else m_SizeLocked = false; deleteIt = false; }
void PageItem_NoteFrame::setNS(NotesStyle *nStyle, PageItem_TextFrame* master) { m_nstyle = nStyle; if (master != NULL) m_masterFrame = master; itemText.clear(); AnName = generateUniqueCopyName(m_nstyle->isEndNotes() ? "Endnote frame " + m_nstyle->name() : "Footnote frame " + m_nstyle->name(), false); setUName(AnName); //set default style for note frame ParagraphStyle newStyle; if (nStyle->notesParStyle().isEmpty() || (nStyle->notesParStyle() == tr("No Style"))) { if (nStyle->isEndNotes() || (m_masterFrame == NULL)) { //set default doc style newStyle.setParent(m_Doc->paragraphStyles()[0].name()); } else if (master != NULL) { newStyle.setParent(m_masterFrame->itemText.defaultStyle().parent()); newStyle.applyStyle(m_masterFrame->currentStyle()); } } else newStyle.setParent(nStyle->notesParStyle()); itemText.blockSignals(true); itemText.setDefaultStyle(newStyle); itemText.blockSignals(false); if (m_nstyle->isAutoNotesHeight()) m_SizeVLocked = true; else m_SizeVLocked = false; if (m_nstyle->isAutoNotesWidth()) m_SizeHLocked = true; else m_SizeHLocked = false; if (m_nstyle->isAutoNotesHeight() && m_nstyle->isAutoNotesWidth()) m_SizeLocked = true; else m_SizeLocked = false; }
void XtgScanner::applyCStyle2() { //apply normal character style sheet <@$> define = 0; flushText(); QString pStyle = CommonStrings::DefaultParagraphStyle; ParagraphStyle newStyle; newStyle.setParent(pStyle); newStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing); currentCharStyle = newStyle.charStyle(); currentCharStyle.setFontSize(120.0); styleEffects = ScStyle_None; currentCharStyle.setFeatures(styleEffects.featureList()); }
void gtAction::write(const QString& text, gtStyle *style, bool isNote) { if (isFirstWrite) { if (!doAppend) { if (it->nextInChain() != 0) { PageItem *nextItem = it->nextInChain(); while (nextItem != 0) { nextItem->itemText.clear(); nextItem = nextItem->nextInChain(); } } it->itemText.clear(); } } int paragraphStyle = -1; if (style->target() == "paragraph") { gtParagraphStyle* pstyle = dynamic_cast<gtParagraphStyle*>(style); assert(pstyle != NULL); paragraphStyle = applyParagraphStyle(pstyle); if (isFirstWrite) inPara = true; } else if (style->target() == "frame") { gtFrameStyle* fstyle = dynamic_cast<gtFrameStyle*>(style); assert(fstyle != NULL); applyFrameStyle(fstyle); } if ((inPara) && (!lastCharWasLineChange) && (text.left(1) != "\n") && (lastParagraphStyle != -1)) paragraphStyle = lastParagraphStyle; if (paragraphStyle == -1) paragraphStyle = 0; //::findParagraphStyle(textFrame->doc(), textFrame->doc()->currentStyle); const ParagraphStyle& paraStyle = textFrame->doc()->paragraphStyles()[paragraphStyle]; gtFont* font = style->getFont(); QString fontName = validateFont(font).scName(); CharStyle lastStyle, newStyle; int lastStyleStart = 0; if ((inPara) && (!overridePStyleFont)) { if (paraStyle.charStyle().font().isNone()) { gtFont font2(*font); font2.setName(paraStyle.charStyle().font().scName()); QString fontName2 = validateFont(&font2).scName(); newStyle.setFont((*textFrame->doc()->AllFonts)[fontName2]); } } else { setCharStyleAttributes(font, newStyle); } /*newStyle.eraseCharStyle(paraStyle.charStyle());*/ lastStyle = newStyle; lastStyleStart = it->itemText.length(); StoryText* story = NULL; if (isNote) { if (noteStory == NULL) { note = it->m_Doc->newNote(it->m_Doc->m_docNotesStylesList.at(0)); noteStory = new StoryText(it->m_Doc); } story = noteStory; } else story = &it->itemText; QChar ch0(0), ch5(5), ch10(10), ch13(13); for (int a = 0; a < text.length(); ++a) { if ((text.at(a) == ch0) || (text.at(a) == ch13)) continue; QChar ch = text.at(a); if ((ch == ch10) || (ch == ch5)) ch = ch13; int pos = story->length(); if (isNote && ch == SpecialChars::OBJECT) { NotesStyle* nStyle = note->notesStyle(); QString label = "NoteMark_" + nStyle->name(); if (nStyle->range() == NSRsection) label += " in section " + it->m_Doc->getSectionNameForPageIndex(it->OwnPage) + " page " + QString::number(it->OwnPage +1); else if (nStyle->range() == NSRpage) label += " on page " + QString::number(it->OwnPage +1); else if (nStyle->range() == NSRstory) label += " in " + it->firstInChain()->itemName(); else if (nStyle->range() == NSRframe) label += " in frame" + it->itemName(); if (it->m_Doc->getMark(label + "_1", MARKNoteMasterType) != NULL) getUniqueName(label,it->m_Doc->marksLabelsList(MARKNoteMasterType), "_"); //FIX ME here user should be warned that inserted mark`s label was changed else label = label + "_1"; Mark* mrk = it->m_Doc->newMark(); mrk->label = label; mrk->setType(MARKNoteMasterType); mrk->setNotePtr(note); note->setMasterMark(mrk); mrk->setString(""); mrk->OwnPage = it->OwnPage; it->itemText.insertMark(mrk); story->applyCharStyle(lastStyleStart, story->length()-lastStyleStart, lastStyle); if (paraStyle.hasName()) { ParagraphStyle pStyle; pStyle.setParent(paraStyle.name()); story->applyStyle(qMax(0,story->length()-1), pStyle); } else story->applyStyle(qMax(0,story->length()-1), paraStyle); lastCharWasLineChange = text.right(1) == "\n"; inPara = style->target() == "paragraph"; lastParagraphStyle = paragraphStyle; if (isFirstWrite) isFirstWrite = false; if (story->text(pos -1) == SpecialChars::PARSEP) story->removeChars(pos-1, 1); note->setSaxedText(saxedText(story)); note = NULL; delete noteStory; noteStory = NULL; return; } else story->insertChars(pos, QString(ch)); if (ch == SpecialChars::PARSEP) { if (paraStyle.hasName()) { ParagraphStyle pstyle; pstyle.setParent(paraStyle.name()); story->applyStyle(pos, pstyle); } else story->applyStyle(pos, paraStyle); } } story->applyCharStyle(lastStyleStart, story->length()-lastStyleStart, lastStyle); if (paraStyle.hasName()) { ParagraphStyle pStyle; pStyle.setParent(paraStyle.name()); story->applyStyle(qMax(0,story->length()-1), pStyle); } else story->applyStyle(qMax(0,story->length()-1), paraStyle); lastCharWasLineChange = text.right(1) == "\n"; inPara = style->target() == "paragraph"; lastParagraphStyle = paragraphStyle; if (isFirstWrite) isFirstWrite = false; }
void gtAction::write(const QString& text, gtStyle *style) { if (isFirstWrite) { if (!doAppend) { if (it->nextInChain() != 0) { PageItem *nextItem = it->nextInChain(); while (nextItem != 0) { nextItem->itemText.clear(); nextItem = nextItem->nextInChain(); } } it->itemText.clear(); } } int paragraphStyle = -1; if (style->target() == "paragraph") { gtParagraphStyle* pstyle = dynamic_cast<gtParagraphStyle*>(style); assert(pstyle != NULL); paragraphStyle = applyParagraphStyle(pstyle); if (isFirstWrite) inPara = true; } else if (style->target() == "frame") { gtFrameStyle* fstyle = dynamic_cast<gtFrameStyle*>(style); assert(fstyle != NULL); applyFrameStyle(fstyle); } if ((inPara) && (!lastCharWasLineChange) && (text.left(1) != "\n") && (lastParagraphStyle != -1)) paragraphStyle = lastParagraphStyle; if (paragraphStyle == -1) paragraphStyle = 0; //::findParagraphStyle(textFrame->doc(), textFrame->doc()->currentStyle); const ParagraphStyle& paraStyle = textFrame->doc()->paragraphStyles()[paragraphStyle]; gtFont* font = style->getFont(); QString fontName = validateFont(font).scName(); CharStyle lastStyle, newStyle; int lastStyleStart = 0; if ((inPara) && (!overridePStyleFont)) { if (paraStyle.charStyle().font().isNone()) { gtFont font2(*font); font2.setName(paraStyle.charStyle().font().scName()); QString fontName2 = validateFont(&font2).scName(); newStyle.setFont((*textFrame->doc()->AllFonts)[fontName2]); } } else { setCharStyleAttributes(font, newStyle); } /*newStyle.eraseCharStyle(paraStyle.charStyle());*/ lastStyle = newStyle; lastStyleStart = it->itemText.length(); QChar ch0(0), ch5(5), ch10(10), ch13(13); for (int a = 0; a < text.length(); ++a) { if ((text.at(a) == ch0) || (text.at(a) == ch13)) continue; QChar ch = text.at(a); if ((ch == ch10) || (ch == ch5)) ch = ch13; else if (ch.unicode() == 0x2028) ch = SpecialChars::LINEBREAK; else if (ch.unicode() == 0x2029) ch = SpecialChars::PARSEP; int pos = it->itemText.length(); it->itemText.insertChars(pos, QString(ch)); if (ch == SpecialChars::PARSEP) { if (paraStyle.hasName()) { ParagraphStyle pstyle; pstyle.setParent(paraStyle.name()); it->itemText.applyStyle(pos, pstyle); } else it->itemText.applyStyle(pos, paraStyle); } } it->itemText.applyCharStyle(lastStyleStart, it->itemText.length()-lastStyleStart, lastStyle); if (paraStyle.hasName()) { ParagraphStyle pStyle; pStyle.setParent(paraStyle.name()); it->itemText.applyStyle(qMax(0,it->itemText.length()-1), pStyle); } else it->itemText.applyStyle(qMax(0,it->itemText.length()-1), paraStyle); lastCharWasLineChange = text.right(1) == "\n"; inPara = style->target() == "paragraph"; lastParagraphStyle = paragraphStyle; if (isFirstWrite) isFirstWrite = false; }
PageItem_NoteFrame::PageItem_NoteFrame(PageItem_TextFrame* inFrame, NotesStyle *nStyle) : PageItem_TextFrame(inFrame->doc(),inFrame->xPos(), inFrame->yPos(),inFrame->width(), inFrame->height(),inFrame->lineWidth(), inFrame->fillColor(), inFrame->lineColor()) { m_nstyle = nStyle; m_masterFrame = inFrame; AnName = generateUniqueCopyName(nStyle->isEndNotes() ? tr("Endnote frame ") + m_nstyle->name() : tr("Footnote frame ") + m_nstyle->name(), false); AutoName = false; setUName(AnName); //set default style for note frame ParagraphStyle newStyle; if (nStyle->notesParStyle().isEmpty() || (nStyle->notesParStyle() == tr("No Style"))) { if (nStyle->isEndNotes()) //set default doc style newStyle.setParent(m_Doc->paragraphStyles()[0].name()); else { newStyle.setParent(m_masterFrame->itemText.defaultStyle().parent()); newStyle.applyStyle(m_masterFrame->currentStyle()); } } else newStyle.setParent(nStyle->notesParStyle()); itemText.blockSignals(true); itemText.setDefaultStyle(newStyle); itemText.blockSignals(false); double frameHeight = calculateLineSpacing(newStyle, this); if (frameHeight == 0.0 && !m_nstyle->isAutoNotesHeight()) frameHeight = newStyle.charStyle().fontSize()/10; m_height = oldHeight = frameHeight; oldWidth = m_width; oldRot = m_rotation; oldXpos = m_xPos; m_yPos = oldYpos =m_masterFrame->yPos() + m_masterFrame->height(); textFlowModeVal = TextFlowUsesFrameShape; setColumns(1); if (m_nstyle->isAutoWeldNotesFrames() && (m_masterFrame != NULL)) { addWelded(m_masterFrame); m_masterFrame->addWelded(this); m_masterFrame->setWeldPoint(0, m_masterFrame->height(), this); setWeldPoint(0,0, m_masterFrame); } if (m_nstyle->isAutoNotesHeight()) m_SizeVLocked = true; else m_SizeVLocked = false; if (m_nstyle->isAutoNotesWidth()) m_SizeHLocked = true; else m_SizeHLocked = false; if (m_nstyle->isAutoNotesHeight() && m_nstyle->isAutoNotesWidth()) m_SizeLocked = true; else m_SizeLocked = false; deleteIt = false; }
void XtgScanner::xtgParse() { /* Enter the default mode as textMode */ enterState(textMode); currentParagraphStyle.setParent(CommonStrings::DefaultParagraphStyle); currentParagraphStyle.charStyle().setParent(CommonStrings::DefaultCharacterStyle); currentParagraphStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing); currentCharStyle = currentParagraphStyle.charStyle(); while (lookAhead() != '\0') { token = getToken(); QHash<QString,void (XtgScanner::*)(void)> *temp = NULL; if (Mode == tagMode) temp = &tagModeHash; else if (Mode == nameMode) temp = &nameModeHash; else if (Mode == textMode) temp = &textModeHash; if (temp->contains(token) ) { funPointer = temp->value(token); (this->*funPointer)(); } /** Various character Style Applications <@stylesheetname>. We cannot hash this since stylesheetname is not constant */ else if ( (currentState() == tagMode ) && token.startsWith('@') && token.endsWith('>') ) { /*here we receive a token @stylesheetname>, hence we have to slice of token to get the name of character stylesheet to be applied */ define = 0; sfcName = token.remove(0,1); sfcName = sfcName.remove(sfcName.size()-1,1); flushText(); // if (styleStatus(definedCStyles,sfcName)) // writer->setCharStyle(sfcName); // else // { // showWarning(sfcName); // writer->setCharStyle(""); // } // currentCharStyle = writer->getCurrentCharStyle(); } if (top >= input_Buffer.length()) break; } if (!textToAppend.isEmpty()) { textToAppend.replace(QChar(10), SpecialChars::LINEBREAK); textToAppend.replace(QChar(12), SpecialChars::FRAMEBREAK); textToAppend.replace(QChar(30), SpecialChars::NBHYPHEN); textToAppend.replace(QChar(160), SpecialChars::NBSPACE); ParagraphStyle newStyle; newStyle.setParent(currentParagraphStyle.name()); int posC = m_item->itemText.length(); m_item->itemText.insertChars(posC, textToAppend); m_item->itemText.applyStyle(posC, newStyle); m_item->itemText.applyCharStyle(posC, textToAppend.length(), currentCharStyle); } // qDebug()<<"Unsupported : "<<unSupported; }
void XtgScanner::definePStyles() { QString s1,s2,s3; enterState(stringMode); define = 2; if (token == "[S\"") s1 = getToken(); else { while (lookAhead() != '\"') top++; //skip the inch top++; s1 = getToken(); //will contain the string 1 } // top = top + 2; //we have to skip comma and next inch character while (lookAhead() != '\"') top++; top++; s2 = getToken(); if (lookAhead() != ']' ) { while (lookAhead() != '\"') top++; top++; // top = top + 2; s3 = getToken(); } top++; // to ensure that ] is avoided QString pStyle = CommonStrings::DefaultParagraphStyle; ParagraphStyle newStyle; if (s1 != "") { if (doc->paragraphStyles().contains(m_item->itemName() + "_" + s1)) newStyle.setParent(m_item->itemName() + "_" + s1); else if (doc->paragraphStyles().contains(s1)) newStyle.setParent(s1); else newStyle.setParent(pStyle); } else newStyle.setParent(pStyle); if (m_prefixName) newStyle.setName(m_item->itemName() + "_" + sfcName); else newStyle.setName((sfcName)); newStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing); if (s3 != "") { if (doc->charStyles().contains(m_item->itemName() + "_" + s3)) newStyle.charStyle().setParent(m_item->itemName() + "_" + s3); else if (doc->charStyles().contains(s3)) newStyle.charStyle().setParent(s3); else newStyle.charStyle().setParent(CommonStrings::DefaultCharacterStyle); } else { newStyle.charStyle().setParent(CommonStrings::DefaultCharacterStyle); newStyle.charStyle().setFontSize(120.0); styleEffects = ScStyle_None; newStyle.charStyle().setFeatures(styleEffects.featureList()); } currentParagraphStyle = newStyle; currentCharStyle = newStyle.charStyle(); enterState(textMode); }