Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Public Member Functions | Public Attributes
SWParse Class Reference

This is the Scribus Short Words plugin main mechanism. More...

#include <parse.h>

List of all members.

Public Member Functions

 SWParse ()
 lightweight constructor
 ~SWParse ()
 nothing here to do
void parseItem (PageItem *aFrame)
 process one frame - base method! Replacing strings via regular expressions.
void parseSelection (ScribusDoc *doc)
 selcted frames on the page
void parsePage (ScribusDoc *doc)
 one page - using actual page
void parsePage (ScribusDoc *doc, int page)
 one page
void parseAll (ScribusDoc *doc)
 all pages in the document

Public Attributes

uint modify
 count of the changes (one frame = one change)

Detailed Description

This is the Scribus Short Words plugin main mechanism.

It walks trough the user specified objects and apply the spaces. This code is based on the Scribus-Vlna plug in rewritten for international use.

Author:
Petr Vanek petr@.nosp@m.yarp.nosp@m.en.cz with contributors.

Definition at line 24 of file parse.h.


Constructor & Destructor Documentation

lightweight constructor

Definition at line 32 of file parse.cpp.

{
       modify = 0;
}
SWParse::~SWParse ( ) [inline]

nothing here to do

Definition at line 32 of file parse.h.

{};

Member Function Documentation

void SWParse::parseAll ( ScribusDoc *  doc)

all pages in the document

Definition at line 162 of file parse.cpp.

{
       for (uint i=0; i < doc->Pages->count(); ++i)
              parsePage(doc, i);
}

Here is the call graph for this function:

void SWParse::parseItem ( PageItem *  aFrame)

process one frame - base method! Replacing strings via regular expressions.

See detailed description in the code of this method.

Parameters:
aFramepointer to the existing text frame

Definition at line 37 of file parse.cpp.

{
       // the content of the frame - text itself
       QString content = QString();
       int changes = 0;
       // language of the frame
       QString lang;
       // list of the short words
       QStringList shorts;
       // text with special space
       QString unbreak;
       // the regexp
       QRegExp rx(" ");
       // cfg
       SWConfig *cfg = new SWConfig();

       // just textframes processed
       if (!aFrame->asTextFrame())
              return;

       // an ugly hack to get the language code from the item language property
       lang = aFrame->itemText.charStyle(0).language();
       if (aFrame->doc()->scMW()->Sprachen.contains(lang))
              lang = cfg->getLangCodeFromHyph(aFrame->doc()->scMW()->Sprachen[lang]);
       // apply spaces after shorts
       shorts = cfg->getShortWords(lang);
       if (shorts.count()==0)
              return; // no changes

       // get text from frame
       int i;
       for (i=0; i < aFrame->itemText.length() && ! aFrame->frameDisplays(i); ++i)
              ;
       for (; i < aFrame->itemText.length() && aFrame->frameDisplays(i); ++i)
              content += aFrame->itemText.text(i,1);
       changes = content.contains(UNBREAKABLE_SPACE);

       // for every config string, replace its spaces by nbsp's.
       for (QStringList::Iterator it = shorts.begin(); it != shorts.end(); ++it)
       {
              unbreak = (*it);
              // replace ' ' from cfg with '~' in the replacement string
              unbreak = unbreak.replace(SPACE, UNBREAKABLE_SPACE);
              /*
              Regexp used to find the config string (*it) in content.
              Cheat sheet:
              - \b is a "word boundary"; it matches at a *position*
              not a *character*
              - \W is a "non-word character"; it matches every character
              that is neither a letter, nor a number, nor '_';
              for example, it matches all kind of whitespace
              (including carriage return) and punctuation
              Example occurrences when (*it) == "Mr ":
                     - "Mr Bla etc." : there's one of the word boundaries
                     of the word "Mr" before the pattern, and one of the
                     word boundaries of the word "Bla" after.
              Example occurrences when (*it) == " !":
                     - "ugly hack ! No." : there's a word boundary before,
                     and a whitespace is matched by \W after.
                     - "» !" : '«' is matched by \W before, newline is
                     matched by \W after.
              */
              rx.setPattern("(\\b|\\W)" + rx.escape(*it) + "(\\b|\\W)");
              /*
              QString::replace works on the whole string in one pass.
              On every occurrence of our regexp, \1 and \2 are replaced
              by what has been matched (captured characters) in,
              respectively, the first and second capturing parentheses.
              */
              content.replace(rx, "\\1" + unbreak + "\\2");
       }
       // return text into frame
       for (i=0; i < aFrame->itemText.length() && ! aFrame->frameDisplays(i); ++i)
              ;
       for (; i < aFrame->itemText.length() && aFrame->frameDisplays(i); ++i)
              aFrame->itemText.replaceChar(i, content.at(i));
       if (content.contains(UNBREAKABLE_SPACE) > changes)
              ++modify;

       delete(cfg);
} // end of method

Here is the call graph for this function:

Here is the caller graph for this function:

void SWParse::parsePage ( ScribusDoc *  doc)

one page - using actual page

Definition at line 132 of file parse.cpp.

{
       parsePage(doc, doc->currentPageNumber());
}

Here is the caller graph for this function:

void SWParse::parsePage ( ScribusDoc *  doc,
int  page 
)

one page

Parameters:
pagepage number

Definition at line 137 of file parse.cpp.

{
       uint cnt = 0;
       uint docItemsCount=doc->Items->count();
       for (uint a = 0; a < docItemsCount; ++a)
       {
              PageItem* b = doc->Items->at(a);
              if (b->OwnPage == page)
                     ++cnt;
       }
       doc->scMW()->mainWindowProgressBar->setTotalSteps(cnt);
       doc->view()->GotoPage(page);
       uint i = 0;
       for (uint a = 0; a < docItemsCount; ++a)
       {
              PageItem* b = doc->Items->at(a);
              if (b->OwnPage == page)
              {
                     doc->scMW()->mainWindowProgressBar->setProgress(++i);
                     parseItem(b);
              }
       }
       doc->scMW()->mainWindowProgressBar->setProgress(cnt);
}

Here is the call graph for this function:

void SWParse::parseSelection ( ScribusDoc *  doc)

selcted frames on the page

Definition at line 119 of file parse.cpp.

{
       uint docSelectionCount = doc->m_Selection->count();
       doc->scMW()->mainWindowProgressBar->setTotalSteps(docSelectionCount);
       for (uint i=0; i < docSelectionCount; ++i)
       {
       doc->scMW()->mainWindowProgressBar->setProgress(i);
              parseItem(doc->m_Selection->itemAt(i));
       } // for items
       doc->scMW()->mainWindowProgressBar->setProgress(docSelectionCount);
}

Here is the call graph for this function:


Member Data Documentation

count of the changes (one frame = one change)

Definition at line 32 of file parse.h.


The documentation for this class was generated from the following files: