void CharSelect::slot_insertUserSpecialChar(QChar ch, QString font) { if (!m_Item) return; PageItem_TextFrame *cItem; if (m_doc->appMode == modeEditTable) cItem = m_Item->asTable()->activeCell().textFrame(); else cItem = m_Item->asTextFrame(); if (cItem->HasSel) cItem->deleteSelectedTextFromFrame(); cItem->invalidateLayout(); // //CB: Avox please make text->insertchar(char) so none of this happens in gui code, and item can tell doc its changed so the view and mainwindow slotdocch are not necessary if (ch == QChar(10)) ch = QChar(13); if (ch == QChar(9)) ch = QChar(32); int pot = cItem->itemText.cursorPosition(); cItem->itemText.insertChars(ch, true); CharStyle nstyle = m_Item->itemText.charStyle(pot); nstyle.setFont((*m_doc->AllFonts)[font]); cItem->itemText.applyCharStyle(pot, 1, nstyle); m_doc->view()->DrawNew(); m_doc->changed(); }
ScFace::gid_type ScFace::hyphenGlyph(const CharStyle& style) const { if (style.hyphenChar() == 0) return SpecialChars::ZWNBSPACE.unicode() + ScFace::CONTROL_GLYPHS; if (style.hyphenChar() == 0x2010) return hyphenGlyph(); return m_m->char2CMap(style.hyphenChar()); }
void PropertiesPalette_Text::updateCharStyle(const CharStyle& charStyle) { if (!m_ScMW || m_ScMW->scriptIsRunning()) return; advancedWidgets->updateCharStyle(charStyle); colorWidgets->updateCharStyle(charStyle); showFontFace(charStyle.font().scName()); showFontSize(charStyle.fontSize()); }
void RTFGenParser::tag_end(const QString &tagName) { // Roll back until we find our tag. bool found = false; for(Tag* pTag = m_tags.peek(); pTag != NULL && !found; pTag = m_tags.peek()) { if (pTag->name == tagName) { found = true; } if (pTag->hasCharStyle()) { CharStyle style = *(pTag->pCharStyle); // We must pop here, so that getTopTagWithCharStyle will find a parent tag. m_tags.pop(); pTag = NULL; // to avoid confusion Tag* pParentTag = m_tags.getTopTagWithCharStyle(); if (pParentTag != NULL) { if (pParentTag->hasCharStyle()) { CharStyle* pParentStyle = pParentTag->pCharStyle; // Roll back the character style. This is regardless of whether // we found the closed tag; we just collapse all styles on our way. QString rtf = pParentStyle->getDiffRTF(style); if (!rtf.isEmpty()) { res += rtf.utf8(); m_bSpace = true; } } } } else // if this tag has no char style attached { m_tags.pop(); // just pop the tag out pTag = NULL; // to avoid confusion } if (found) { if (tagName.lower() == "p") { res += "\\par"; m_bSpace = true; } } } }
void CharStyle::setStyle(const CharStyle& other) { other.validate(); setParent(other.parent()); m_contextversion = -1; #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \ inh_##attr_NAME = other.inh_##attr_NAME; \ m_##attr_NAME = other.m_##attr_NAME; #include "charstyle.attrdefs.cxx" #undef ATTRDEF updateFeatures(); }
void PropertyWidget_Advanced::updateCharStyle(const CharStyle& charStyle) { if (!m_ScMW || m_ScMW->scriptIsRunning()) return; showTextScaleH(charStyle.scaleH()); showTextScaleV(charStyle.scaleV()); showTracking(charStyle.tracking()); showBaseLineOffset(charStyle.baselineOffset()); normWordTrackingSpinBox->showValue(charStyle.wordTracking() * 100.0); }
void CharStyle::applyCharStyle(const CharStyle & other) { if (other.hasParent() && (other.parent() != Style::INHERIT_PARENT)) { setStyle(other); return; } Style::applyStyle(other); #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \ if (! other.inh_##attr_NAME) \ set##attr_NAME(other.m_##attr_NAME); #include "charstyle.attrdefs.cxx" #undef ATTRDEF updateFeatures(); }
void TestStoryText::removeCharStyle() { StoryText story; story.insertChars(0, QString("0123456789") + SpecialChars::PARSEP + QString("abcdefghijklmnopqrstuvwxyz") + SpecialChars::PARSEP + QString("ABCDEFGHIJKLMNOPQRSTUVWXYZ")); QCOMPARE(story.nrOfRuns(), 3u); CharStyle cs; cs.setFontSize(10); story.applyCharStyle(5 + 26 + 1, 26 + 1, cs); story.removeChars(11, 26+1); QCOMPARE(story.nrOfRuns(), 3u); QCOMPARE(story.startOfRun(0), 0); QCOMPARE(story.endOfRun(0), 11); QCOMPARE(story.startOfRun(1), 11); QCOMPARE(story.endOfRun(1), 5 + 26 + 1); QCOMPARE(story.startOfRun(2), 5 + 26 + 1); QCOMPARE(story.endOfRun(2), 11 + 26); }
void CharStyle::eraseCharStyle(const CharStyle & other) { other.validate(); Style::eraseStyle(other); #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \ if (!inh_##attr_NAME && m_##attr_NAME == other.m_##attr_NAME) \ reset##attr_NAME(); #include "charstyle.attrdefs.cxx" #undef ATTRDEF updateFeatures(); }
void gtAction:: setCharStyleAttributes(gtFont *font, CharStyle& style) { int flags = font->getFlags(); style.erase(); if ((flags & gtFont::familyWasSet) || (flags & gtFont::weightWasSet) || (flags & gtFont::slantWasSet)) style.setFont(validateFont(font)); if (flags & gtFont::sizeWasSet) style.setFontSize(font->getSize()); if (flags & gtFont::effectWasSet) style.setFeatures(static_cast<StyleFlag>(font->getEffectsValue()).featureList()); if (flags & gtFont::fillColorWasSet) style.setFillColor(parseColor(font->getColor())); if (flags & gtFont::fillShadeWasSet) style.setFillShade(font->getShade()); if (flags & gtFont::strokeColorWasSet) style.setStrokeColor(parseColor(font->getStrokeColor())); if (flags & gtFont::strokeShadeWasSet) style.setStrokeShade(font->getStrokeShade()); if (flags & gtFont::hscaleWasSet) style.setScaleH(font->getHscale()); if (flags & gtFont::kerningWasSet) style.setTracking(font->getKerning()); }
void CharSelect::slot_insertSpecialChar() { emit insertSpecialChar(); if (!m_Item) return; PageItem_TextFrame *cItem; if (m_doc->appMode == modeEditTable) cItem = m_Item->asTable()->activeCell().textFrame(); else cItem = m_Item->asTextFrame(); if (cItem->HasSel) cItem->deleteSelectedTextFromFrame(); cItem->invalidateLayout(); //CB: Avox please make text->insertchar(char) so none of this happens in gui code, and item can tell doc its changed so the view and mainwindow slotdocch are not necessary QChar ch; QString fontName = m_doc->currentStyle.charStyle().font().scName(); if (m_enhanced) fontName = m_enhanced->getUsedFont(); for (int a=0; a<chToIns.length(); ++a) { ch = chToIns.at(a); if (ch == QChar(10)) ch = QChar(13); if (ch == QChar(9)) ch = QChar(32); int pot = cItem->itemText.cursorPosition(); cItem->itemText.insertChars(ch, true); CharStyle nstyle = m_Item->itemText.charStyle(pot); nstyle.setFont((*m_doc->AllFonts)[fontName]); cItem->itemText.applyCharStyle(pot, 1, nstyle); } m_doc->view()->DrawNew(); m_doc->changed(); // delEdit(); }
/*! 03.01.2007 - 05.01.2007 : Joachim Neu : Create a char style. Special thanks go to avox for helping me! */ PyObject *scribus_createcharstyle(PyObject* /* self */, PyObject* args, PyObject* keywords) { char* keywordargs[] = { const_cast<char*>("name"), const_cast<char*>("font"), const_cast<char*>("fontsize"), const_cast<char*>("features"), const_cast<char*>("fillcolor"), const_cast<char*>("fillshade"), const_cast<char*>("strokecolor"), const_cast<char*>("strokeshade"), const_cast<char*>("baselineoffset"), const_cast<char*>("shadowxoffset"), const_cast<char*>("shadowyoffset"), const_cast<char*>("outlinewidth"), const_cast<char*>("underlineoffset"), const_cast<char*>("underlinewidth"), const_cast<char*>("strikethruoffset"), const_cast<char*>("strikethruwidth"), const_cast<char*>("scaleh"), const_cast<char*>("scalev"), const_cast<char*>("tracking"), const_cast<char*>("language"), NULL}; char *Name = const_cast<char*>(""), *Font = const_cast<char*>("Times"), *Features = const_cast<char*>("inherit"), *FillColor = const_cast<char*>("Black"), *StrokeColor = const_cast<char*>("Black"), *Language = const_cast<char*>(""); double FontSize = 200, FillShade = 1, StrokeShade = 1, ScaleH = 1, ScaleV = 1, BaselineOffset = 0, ShadowXOffset = 0, ShadowYOffset = 0, OutlineWidth = 0, UnderlineOffset = 0, UnderlineWidth = 0, StrikethruOffset = 0, StrikethruWidth = 0, Tracking = 0; if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|esdesesdesddddddddddddes", keywordargs, "utf-8", &Name, "utf-8", &Font, &FontSize, "utf-8", &Features, "utf-8", &FillColor, &FillShade, "utf-8", &StrokeColor, &StrokeShade, &BaselineOffset, &ShadowXOffset, &ShadowYOffset, &OutlineWidth, &UnderlineOffset, &UnderlineWidth, &StrikethruOffset, &StrikethruWidth, &ScaleH, &ScaleV, &Tracking, "utf-8", &Language)) return NULL; if(!checkHaveDocument()) return NULL; if(Name == EMPTY_STRING) { PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty char style name.","python error").toLocal8Bit().constData()); return NULL; } QStringList FeaturesList = QString(Features).split(QString(",")); CharStyle TmpCharStyle; TmpCharStyle.setName(Name); TmpCharStyle.setFont((*ScCore->primaryMainWindow()->doc->AllFonts)[QString(Font)]); TmpCharStyle.setFontSize(FontSize * 10); TmpCharStyle.setFeatures(FeaturesList); TmpCharStyle.setFillColor(QString(FillColor)); TmpCharStyle.setFillShade(FillShade * 100); TmpCharStyle.setStrokeColor(QString(StrokeColor)); TmpCharStyle.setStrokeShade(StrokeShade * 100); TmpCharStyle.setBaselineOffset(BaselineOffset); TmpCharStyle.setShadowXOffset(ShadowXOffset); TmpCharStyle.setShadowYOffset(ShadowYOffset); TmpCharStyle.setOutlineWidth(OutlineWidth); TmpCharStyle.setUnderlineOffset(UnderlineOffset); TmpCharStyle.setUnderlineWidth(UnderlineWidth); TmpCharStyle.setStrikethruOffset(StrikethruOffset); TmpCharStyle.setStrikethruWidth(StrikethruWidth); TmpCharStyle.setScaleH(ScaleH * 1000); TmpCharStyle.setScaleV(ScaleV * 1000); TmpCharStyle.setTracking(Tracking); TmpCharStyle.setLanguage(QString(Language)); StyleSet<CharStyle> TmpStyleSet; TmpStyleSet.create(TmpCharStyle); ScCore->primaryMainWindow()->doc->redefineCharStyles(TmpStyleSet, false); // PV - refresh the Style Manager window. // I thought that this can work but it doesn't: // ScCore->primaryMainWindow()->styleMgr()->reloadStyleView(); // So the brute force setDoc is called... ScCore->primaryMainWindow()->styleMgr()->setDoc(ScCore->primaryMainWindow()->doc); Py_RETURN_NONE; }
string RTFGenParser::parse(const QString &text) { res = ""; m_res_size = 0; m_codec = getContacts()->getCodec(m_contact); int charset = 0; for (const ENCODING *c = getContacts()->getEncodings(); c->language; c++){ if (!strcasecmp(c->codec, m_codec->name())){ charset = c->rtf_code; break; } } #ifdef WIN32 if ((charset == 0) && !strcasecmp(m_codec->name(), "system")){ char buff[256]; int res = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, (char*)&buff, sizeof(buff)); if (res){ unsigned codepage = atol(buff); if (codepage){ for (const rtf_cp *c = rtf_cps; c->cp; c++){ if (c->cp == codepage) charset = c->charset; } } } } #endif unsigned ansicpg = 0; const char *send_encoding = 0; m_codec = NULL; if (charset){ for (const ENCODING *c = getContacts()->getEncodings(); c->language; c++){ if ((c->rtf_code == charset) && c->bMain){ send_encoding = c->codec; m_codec = getContacts()->getCodecByName(send_encoding); ansicpg = c->cp_code; break; } } } // Add defaults to the tables m_fontFaces.push_back("MS Sans Serif"); m_colors.push_back(m_foreColor); // Create a "fake" tag which'll serve as the default style CharStyle style; style.faceIdx = 0; style.colorIdx = 1; // colors are 1-based (0 = default) style.sizePt = 12; // default according to Microsoft Tag& tag = *(m_tags.pushNew()); tag.setCharStyle(style); // Assume we go immediately after a tag. m_bSpace = true; HTMLParser::parse(text); string s; s = "{\\rtf1\\ansi"; if (ansicpg){ s += "\\ansicpg"; s += number(ansicpg); } s += "\\deff0\r\n"; s += "{\\fonttbl"; unsigned n = 0; for (list<QString>::iterator it_face = m_fontFaces.begin(); it_face != m_fontFaces.end(); it_face++, n++){ s += "{\\f"; s += number(n); QString face = (*it_face); if (face.find("Times") >= 0){ s += "\\froman"; }else if (face.find("Courier") >= 0){ s += "\\fmodern"; }else{ s += "\\fswiss"; } if (charset){ s += "\\fcharset"; s += number(charset); } s += " "; int pos = face.find(QRegExp(" +[")); if (pos > 0) face = face.left(pos); s += static_cast<string>(face.toLatin1()); s += ";}"; } s += "}\r\n"; s += "{\\colortbl ;"; for (list<QColor>::iterator it_colors = m_colors.begin(); it_colors != m_colors.end(); ++it_colors){ QColor c = *it_colors; s += "\\red"; s += number(c.red()); s += "\\green"; s += number(c.green()); s += "\\blue"; s += number(c.blue()); s += ";"; } s += "}\r\n"; s += "\\viewkind4\\pard"; s += static_cast<string>(style.getDiffRTF(CharStyle()).toUtf8()); s += res; s += "\r\n}\r\n"; log(L_DEBUG, "Resulting RTF: %s", s.c_str()); return s; }
double ScFace::hyphenWidth(const CharStyle& style, qreal size) const { if (style.hyphenChar() == 0) return 0; return glyphBBox(hyphenGlyph(style), size).width; }
void PropertyWidget_TextColor::updateCharStyle(const CharStyle& charStyle) { if (!m_ScMW || m_ScMW->scriptIsRunning()) return; showOutlineW (charStyle.outlineWidth()); showShadowOffset(charStyle.shadowXOffset(), charStyle.shadowYOffset()); showTextColors(charStyle.strokeColor(), charStyle.fillColor(), charStyle.strokeShade(), charStyle.fillShade()); showTextEffects(charStyle.effects()); showStrikeThru(charStyle.strikethruOffset() , charStyle.strikethruWidth()); showUnderline (charStyle.underlineOffset(), charStyle.underlineWidth()); }
void SearchReplace::slotDoReplace() { if (m_itemMode) { QString repl, sear; int cs, cx; int textLen = 0; if (RText->isChecked()) { repl = RTextVal->text(); sear = STextVal->text(); textLen = m_item->itemText.lengthOfSelection(); if (textLen == repl.length()) { for (cs = 0; cs < textLen; ++cs) m_item->itemText.replaceChar(m_replStart+cs, repl[cs]); } else { if (textLen < repl.length()) { for (cs = 0; cs < textLen; ++cs) m_item->itemText.replaceChar(m_replStart+cs, repl[cs]); for (cx = cs; cx < repl.length(); ++cx) m_item->itemText.insertChars(m_replStart+cx, repl.mid(cx,1), true); } else { for (cs = 0; cs < repl.length(); ++cs) m_item->itemText.replaceChar(m_replStart+cs, repl[cs]); m_item->itemText.removeChars(m_replStart+cs, textLen - cs); } } m_item->itemText.deselectAll(); if (repl.length() > 0) { m_item->itemText.select(m_replStart, repl.length()); m_item->itemText.setCursorPosition(m_replStart + repl.length()); } } if (RStyle->isChecked()) { int oldMode = m_doc->appMode; m_doc->appMode = modeEdit; m_doc->itemSelection_SetNamedParagraphStyle(m_doc->paragraphStyles()[RStyleVal->currentIndex()].name()); m_doc->appMode = oldMode; } if (RAlign->isChecked()) { int oldMode = m_doc->appMode; m_doc->appMode = modeEdit; m_doc->itemSelection_SetAlignment(RAlignVal->currentIndex()); m_doc->appMode = oldMode; } if (RFill->isChecked()) m_doc->itemSelection_SetFillColor(RFillVal->currentText()); if (RFillS->isChecked()) m_doc->itemSelection_SetFillShade(RFillSVal->getValue()); if (RStroke->isChecked()) m_doc->itemSelection_SetStrokeColor(RStrokeVal->currentText()); if (RStrokeS->isChecked()) m_doc->itemSelection_SetStrokeShade(RStrokeSVal->getValue()); if (RFont->isChecked()) m_doc->itemSelection_SetFont(RFontVal->currentText()); if (RSize->isChecked()) m_doc->itemSelection_SetFontSize(qRound(RSizeVal->value() * 10.0)); if (REffect->isChecked() && (m_item->itemText.lengthOfSelection() > 0)) { int s = REffVal->getStyle() & ScStyle_UserStyles; m_doc->currentStyle.charStyle().setFeatures(static_cast<StyleFlag>(s).featureList()); // ??? for (int a = 0; a < m_item->itemText.length(); ++a) { if (m_item->itemText.selected(a)) { // StyleFlag fl = m_item->itemText.charStyle(a).effects(); // fl &= static_cast<StyleFlag>(~1919); // fl |= static_cast<StyleFlag>(s); // m_item->itemText.item(a)->setFeatures(fl.featureList()); CharStyle newFeatures; newFeatures.setFeatures(static_cast<StyleFlag>(s).featureList()); m_item->itemText.applyCharStyle(a, 1, newFeatures); } } } m_item->itemText.deselectAll(); } else if (m_doc->scMW()->CurrStED != NULL) { StoryEditor* se = m_doc->scMW()->CurrStED; if (RText->isChecked()) { disconnect(se->Editor, SIGNAL(cursorPositionChanged()), se, SLOT(updateProps())); int SelStart = se->Editor->textCursor().selectionStart(); int SelEnd = se->Editor->textCursor().selectionEnd(); // se->Editor->insChars(RTextVal->text()); se->Editor->textCursor().setPosition(SelStart); se->Editor->textCursor().setPosition(SelEnd, QTextCursor::KeepAnchor); se->Editor->textCursor().removeSelectedText(); //FIXME se->Editor->setEffects(se->Editor->CurrentEffects); QString newText = RTextVal->text(); se->Editor->insertPlainText(newText); if (newText.length() > 0) { QTextCursor textCursor = se->Editor->textCursor(); textCursor.setPosition(SelStart); textCursor.setPosition(SelStart + newText.length(), QTextCursor::KeepAnchor); se->Editor->setTextCursor(textCursor); } connect(se->Editor, SIGNAL(cursorPositionChanged()), se, SLOT(updateProps())); // se->newAlign(se->Editor->currentParaStyle); } if (RStyle->isChecked()) se->newStyle(m_doc->paragraphStyles()[RStyleVal->currentIndex()].name()); if (RAlign->isChecked()) se->newAlign(RAlignVal->currentIndex()); if (RFill->isChecked()) se->newTxFill(RFillVal->currentIndex(), -1); if (RFillS->isChecked()) se->newTxFill(-1, RFillSVal->getValue()); if (RStroke->isChecked()) se->newTxStroke(RStrokeVal->currentIndex(), -1); if (RStrokeS->isChecked()) se->newTxStroke(-1, RStrokeSVal->getValue()); if (RFont->isChecked()) se->newTxFont(RFontVal->currentText()); if (RSize->isChecked()) se->newTxSize(RSizeVal->value()); if (REffect->isChecked()) se->newTxStyle(REffVal->getStyle()); QTextCursor textCursor = se->Editor->textCursor(); int selStart = textCursor.selectionStart(); int selEnd = textCursor.selectionEnd(); int selPos = qMax(selStart, selEnd); textCursor.setPosition(selPos); se->Editor->setTextCursor(textCursor); } DoReplace->setEnabled(false); AllReplace->setEnabled(false); slotDoSearch(); }