Scribus API for plugins
A stable, high level and documented interface to the Scribus core that plugin developers can use to access the Scribus features.
Public Member Functions | List of all members
ScribusAPIDocumentItemText Class Reference
Inheritance diagram for ScribusAPIDocumentItemText:
Inheritance graph
[legend]
Collaboration diagram for ScribusAPIDocumentItemText:
Collaboration graph
[legend]

Public Member Functions

 ScribusAPIDocumentItemText (ScribusAPIDocumentItem *documentItem)
 
bool isFirstInChain ()
 
bool isEmpty ()
 
QVector< ScribusAPIDocumentItemTextRunsgetStoryRuns ()
 Get the runs for the full story of the text frame. More...
 
QVector< ScribusAPIDocumentItemTextRunsgetRuns ()
 Get the runs in the text frame. More...
 
QVector< ScribusAPIDocumentItemTextRunsgetRuns (int start, int end)
 Parse the text and define the runs list. More...
 
QList< QDomElement > getDom (QDomDocument xhtmlDocument)
 
ScribusAPIDocumentItemTextFormatting getFormattingAtPosition (int position)
 
int getLength ()
 Get the number of characters in the frame.
 
int getStoryLength ()
 
void setCursorPosition (int position)
 
void insert (const QString text, const QString paragraphStyle="", const QString characterStyle="")
 Insert text at the current cursor position. More...
 
void append (const QString text, const QString paragraphStyle="", const QString characterStyle="")
 Append text at the end of the chain of text frames. More...
 
void appendParagraph (const QString text, const QString paragraphStyle="")
 Append a paragraph at the end of the chain of text frames. More...
 
void applyParagraphStyle (const QString styleName)
 Apply the paragraph style at the current cursor position. More...
 
void applyParagraphStyle (int position, const QString styleName)
 Apply the paragraph style at a specific position.
 
void applyCharacterStyle (const QString styleName)
 Apply the character style at the current cursor position. More...
 

Member Function Documentation

◆ append()

void ScribusAPIDocumentItemText::append ( const QString  text,
const QString  paragraphStyle = "",
const QString  characterStyle = "" 
)

Append text at the end of the chain of text frames.

The cursor is moved to the end of the text in the chain.

Todo:
: implement it.

◆ appendParagraph()

void ScribusAPIDocumentItemText::appendParagraph ( const QString  text,
const QString  paragraphStyle = "" 
)

Append a paragraph at the end of the chain of text frames.

If the story is not empty, add a new line before inserting the text. The cursor does not move.

◆ applyCharacterStyle()

void ScribusAPIDocumentItemText::applyCharacterStyle ( const QString  styleName)

Apply the character style at the current cursor position.

Todo:
:
  • apply the style depending on the "type" of the current selection:
    • to the whole frame if a frame is selected
    • to the whole paragraphs in the selection if there is a selection
    • to the whole current paragraph if there is no selection but the cursor is in edit mode.
    • have a look at void ScribusDoc::itemSelection_SetNamedCharStyle(const QString& name, Selection* customSelection)

◆ applyParagraphStyle()

void ScribusAPIDocumentItemText::applyParagraphStyle ( const QString  styleName)

Apply the paragraph style at the current cursor position.

Todo:
:
  • apply the style depending on the "type" of the current selection:
    • to the whole frame if a frame is selected
    • to the whole paragraphs in the selection if there is a selection
    • to the whole current paragraph if there is no selection but the cursor is in edit mode.
    • have a look at void ScribusDoc::itemSelection_SetNamedCharStyle(const QString& name, Selection* customSelection)
    • a different approach might use the story-applyStyle(pos, style) used in gtaction.cpp
    • it probably only works if we are already in edit mode and the cursor has a position

a good example for applying the paragraph style seems to be void ScribusMainWindow::setNewCharStyle(const QString& name) in scribus.cpp, which is called from the properties palette.

◆ getDom()

QList< QDomElement > ScribusAPIDocumentItemText::getDom ( QDomDocument  xhtmlDocument)

example of charStyle() use in svgexplugin.cpp cf. short-words/parse.cpp cf. Scribus150Format::writeITEXTs() for getting the local formatting in plugins/fileloader/scribus150format/scribus150format_save.cpp

  • get the list of runs (chunks different formatting) in the text frame
  • foreach run:
    • if it's a p
      • create a p element with it's style name
      • set this element as the latest inserted paragraph
      • set the the dom element as the current one
    • get the character style
    • get the local formatting of the first char in the run
      • font name
        • if the the font name suggests an italic or bold add italic or bold to the list of the formatting
    • foreach formatting (feature)
      • if it's bold, italic, superscript, subscript create an element with the specfic tag
      • if it's underline, strikethrough add the formatting to the span's style attribute
    • if there is a character style of a local formatting:
      • if not specific tag has been createdi create a span element
      • add the class and style attributes to the element
      • add the span to the paragraph element and set it as the current element
    • insert the text line by line (with a br at the end of each but the last line)
    • add the p to the dom
    • set the current element as the latest element paragraph created
      Todo:
      :

◆ getRuns() [1/2]

QVector< ScribusAPIDocumentItemTextRuns > ScribusAPIDocumentItemText::getRuns ( )

Get the runs in the text frame.

See also
getRuns(int start, int end) for more details.

◆ getRuns() [2/2]

QVector< ScribusAPIDocumentItemTextRuns > ScribusAPIDocumentItemText::getRuns ( int  start,
int  end 
)

Parse the text and define the runs list.

Get the runs for a specific range in the story.

Runs are strings with a common formatting. The paragraph mark ends the run.

this method is based on pierre's work for the mitical OIF branch ... also inspired by Scribus150Format::writeITEXTs

Todo:
:
  • use the text/storytext methods as soon as they are implemented

◆ getStoryRuns()

QVector< ScribusAPIDocumentItemTextRuns > ScribusAPIDocumentItemText::getStoryRuns ( )

Get the runs for the full story of the text frame.

When looping through all the items in a document, you will probably want to check if the current item is the beginning of a chain before calling getStoryRuns().

See also
getRuns(int start, int end) for more details.

◆ insert()

void ScribusAPIDocumentItemText::insert ( const QString  text,
const QString  paragraphStyle = "",
const QString  characterStyle = "" 
)

Insert text at the current cursor position.

Insert the text before the cursor position.

Use append() to insert text after the last character.


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