Led 3.0 Class Library Documentation

Module StyledTextIO


Classes and Global Functions Index

Module Description:

A portable attempt at abstracting away the details of styled text file IO and all the different formats for styled text.

This code defines APIs which should allow for reading any different styled text format. And dumping it to any different output (eg. text buffer).

The only real LED-SPECIFIC parts of this are that I only provide concrete output (aka sinks) implementations to Led StandardStyledTextImagers. And that some of the Src/Sink APIs are oriented towards what would be helpful for a Led-based editor (in other words, features not supported by Led aren't communicated to/from the src/sinks).

The big picture for this module is that there are two main basic subdivisions. There are StyledTextIOReader subclasses, and StyledTextIOWriter subclasses. The readers are for READING some file format, and converting it to a stream of method calls (on a sink to be described later). And writers are for writing those formatted data files, based on results of method calls on an abstract source class.

Though StyledTextIOReader and StyledTextIOWriter share no common base class, they do follow a very similar design pattern. They both define abstract 'sources' and 'sinks' for their operation.

For a StyledTextIOReader, it reads its data from a StyledTextIOReader::SrcStream (typically maybe a file), and writes it to a StyledTextIOReader::SinkStream (typically a Led-text-buffer/view).

A StyledTextIOWriter, writes data extracted from a StyledTextIOWriter::SrcStream (typically view/textstore, much like a StyledTextIOReader::SinkStream), and writes it to a StyledTextIOWriter::SinkStream (typically an output file).

These abstract sources and sinks are defined to just the minimal pure virtual APIs needed to extract/write bare bytes, or formatted text in a format Led can understand. Several concrete instantiations of each are provided by Led (some here, and some in other modules, as appropriate).

Subclasses of StyledTextIOReader and StyledTextIOWriter are where the knowledge of particular file formats resides. For example, the knowledge of how to read RTF is in StyledTextIOReader_RTF and the knowledge of how to write HTML is in StyledTextIOWriter_HTML.


Class: EmbeddingSinkStream [public]

Base Classes: SimpleEmbeddedObjectStyleMarker::SinkStream
Description:

Class: StyledTextIOReader [public]

Description:

Abstract base class for styled text reading. Subclasses know about various styled text file formats, and take care of the details of mapping streams of bytes into Led internal data structures with that styled text.

Member Details

StyledTextIOReader::GetBadInputHandler [public]

Led_RefCntPtr < StyledTextIOReader::BadInputHandler > StyledTextIOReader::GetBadInputHandler () const

Each reader class has associated with it an error handler - of type StyledTextIOReader::BadInputHandler. This is used to handle syntactic or logical errors in the input. By default - this class is simple StyledTextIOReader::BadInputHandler.

See also StyledTextIOReader::SetBadInputHandler and StyledTextIOReader::HandleBadlyFormattedInput.

StyledTextIOReader::HandleBadlyFormattedInput [public]

void StyledTextIOReader::HandleBadlyFormattedInput (bool unrecoverable) const

This routine is called whenever this is badly formatted input text to the reader. This is a simple wrapper on the owned StyledTextIOReader::BadInputHandler, which can be gotten/set with StyledTextIOReader::GetBadInputHandler / StyledTextIOReader::SetBadInputHandler

StyledTextIOReader::PutBackLastChar [public]

void StyledTextIOReader::PutBackLastChar () const

Unread the last read character. Note - this can be done as many times as you want (allowing infinite unread) but it is a bug/error if you ever unread characters that handn't been read in the first place

StyledTextIOReader::SetBadInputHandler [public]

void StyledTextIOReader::SetBadInputHandler (const Led_RefCntPtr < BadInputHandler > & badInputHandler)

See StyledTextIOReader::GetBadInputHandler


Class: StyledTextIOReader::BadInputHandler [public]

Description:

Abstract base class for styled text writing. Subclasses know about various styled text file formats, and take care of the details of mapping Led internal data structures with styled text into streams of bytes in that format.

Member Details

StyledTextIOReader::BadInputHandler::HandleBadlyFormattedInput [public]

void StyledTextIOReader::BadInputHandler::HandleBadlyFormattedInput (const StyledTextIOReader& /*reader*/, bool unrecoverable)

This routine is called whenever this is badly formatted input text to the reader. By default - this routine does nothing (unless the unrecoverable argument is 'true').

This is a change of behavior from Led 2.3. In Led 2.3 - format errors would always throw by calling Led_ThrowBadFormatDataException. Instead - this method now calls this virtual method of StyledTextIOReader::BadInputHandler - which your subclass can override to throw Led_ThrowBadFormatDataException - if thats the behavior you want. You can replace the error handler associated with a particular StyledTextIOReader by calling StyledTextIOReader::SetBadInputHandler.


Class: StyledTextIOReader::SinkStream [public]

Description:

A StyledTextIOReader needs a pointer to a function which is a sink for all the styled text and other information read. SinkStream is an abstract class defining this API.

Member Details

StyledTextIOReader::SinkStream::AppendEmbedding [public]

virtual void AppendEmbedding (SimpleEmbeddedObjectStyleMarker* embedding) = 0;

StyledTextIOReader::SinkStream::AppendSoftLineBreak [public]

virtual void AppendSoftLineBreak () = 0;

StyledTextIOReader::SinkStream::AppendText [public]

virtual void AppendText (const Led_tChar* text, size_t nTChars, const Led_FontSpecification* fontSpec) = 0;

Append the given text to the output text buffer. If fontSpec is NULL, use default. Probably later we will return and update the fontspec with StyledTextIOReader::SinkStream::ApplyStyle. Note, this style of API is defined cuz some format readers give us a bunch of text at once, and then later (elsewhere) store the style information. And still others provide them together, hand-in-hand.

StyledTextIOReader::SinkStream::ApplyStyle [public]

virtual void ApplyStyle (size_t from, size_t to, const vector < StandardStyledTextImager::InfoSummaryRecord > & styleRuns) = 0;

Apply the given style information to the given range of text. See StyledTextIOReader::SinkStream::AppendText.

StyledTextIOReader::SinkStream::EndOfBuffer [public]

virtual void EndOfBuffer () {};

Called by StyledText IO readers when end of source buffer is encountered. This means that the next Flush () call contains the last of the text.

StyledTextIOReader::SinkStream::Flush [public]

virtual void Flush () = 0;

StyledTextIOReader::SinkStream::GetCountOfTCharsInserted [public]

size_t StyledTextIOReader::SinkStream::GetCountOfTCharsInserted () const

StyledTextIOReader::SinkStream::GetDefaultFontSpec [public]

virtual Led_FontSpecification GetDefaultFontSpec () const = 0;

StyledTextIOReader::SinkStream::InsertEmbeddingForExistingSentinal [public]

virtual void InsertEmbeddingForExistingSentinal (SimpleEmbeddedObjectStyleMarker* embedding, size_t at) = 0;

StyledTextIOReader::SinkStream::InsertMarker [public]

virtual void InsertMarker (Marker* m, size_t at, size_t length, MarkerOwner* markerOwner) = 0;

StyledTextIOReader::SinkStream::SetLineSpacing [public]

void StyledTextIOReader::SinkStream::SetLineSpacing (Led_LineSpacing /*sl*/)

StyledTextIOReader::SinkStream::SetSpaceAfter [public]

void StyledTextIOReader::SinkStream::SetSpaceAfter (Led_TWIPS /*sa*/)

StyledTextIOReader::SinkStream::SetSpaceBefore [public]

void StyledTextIOReader::SinkStream::SetSpaceBefore (Led_TWIPS /*sb*/)

StyledTextIOReader::SinkStream::current_offset [public]

virtual size_t current_offset () const = 0; // current seekPos

Return the current seekPos


Class: StyledTextIOReader::SrcStream [public]

Description:

A StyledTextIOReader needs a pointer to a function which is a source of raw bytes to be interpretted as text which will be inserted into a text buffer. SrcStream is an abstract class defining this API.

Member Details

StyledTextIOReader::SrcStream::GetAUXResourceHandle [public]

virtual Handle GetAUXResourceHandle () const = 0;

MacOS Only. Returns the Mac handle to the resource fork, if any (used to read 'styl' resources).

StyledTextIOReader::SrcStream::current_offset [public]

virtual size_t current_offset () const = 0;

Return the current seekPos

StyledTextIOReader::SrcStream::read [public]

virtual size_t read (void* buffer, size_t bytes) = 0;

Read the given number of bytes from the is source, and fill them into the buffer. Returns the number of bytes read.

StyledTextIOReader::SrcStream::seek_to [public]

virtual void seek_to (size_t to) = 0;

Sets the current read-pointer to the given position (often used to scan backwards, but can be any direction). Note if 'to' is past end, this just pins one past end of buffer.


Class: StyledTextIOSrcStream_FileDescriptor [public]

Base Classes: StyledTextIOReader::SrcStream
Description:

If you have a file which contains the untyped contents which will be converted by some reader (StyledTextIOReader), you use this as the StyledTextIOReader::SrcStream. Just initialize one of these with the open file descriptor, and pass this to the appropriate StyledTextIOReader.

NB: This class doesn't close the argument file descriptor. It is up the the caller todo that, and only after this SrcStream object has been destroyed. Typically, this follows trivially from a sequential, stack-based allocation strategy, where the data comes from some object declared earlier on the stack.


Class: StyledTextIOSrcStream_Memory [public]

Base Classes: StyledTextIOReader::SrcStream
Description:

If you have a block of memory which contains the untyped contents which will be converted by some reader (StyledTextIOReader), you use this as the StyledTextIOReader::SrcStream. Just initialize one of these with the appropriate data, and pass this to the appropriate StyledTextIOReader.

NB: This class doesn't free up, or copy the given pointer. It is up the the caller todo that, and only after this SrcStream object has been destroyed. Typically, this follows trivially from a sequential, stack-based allocation strategy, where the data comes from some object declared earlier on the stack.


Class: StyledTextIOWriter [public]

Description:

Abstract base class for styled text writing. Subclasses know about various styled text file formats, and take care of the details of mapping Led internal data structures with styled text into streams of bytes in that format.


Class: StyledTextIOWriter::SinkStream [public]

Description:

Abstract base class for StyledTextIOWriters to dump their text content to.

Member Details

StyledTextIOWriter::SinkStream::current_offset [public]

virtual size_t current_offset () const = 0;

Return the current seekPos.

StyledTextIOWriter::SinkStream::seek_to [public]

virtual void seek_to (size_t to) = 0;

'to' past end just pins one past end of buffer

StyledTextIOWriter::SinkStream::write [public]

virtual void write (const void* buffer, size_t bytes) = 0;


Class: StyledTextIOWriter::SrcStream [public]

Description:

Abstract base class for StyledTextIOWriters to get their text content from.

Member Details

StyledTextIOWriter::SrcStream::CollectAllEmbeddingMarkersInRange [public]

virtual vector < SimpleEmbeddedObjectStyleMarker* >

StyledTextIOWriter::SrcStream::GetEmbeddingMarkerPosOffset [public]

virtual size_t GetEmbeddingMarkerPosOffset () const = 0;

Since we maybe externalizing a subset of the buffer, and the marker positions in the embedding object are absolute, we need to know this to relativize them in the externalized stream

StyledTextIOWriter::SrcStream::GetFirstIndent [public]

Led_TWIPS StyledTextIOWriter::SrcStream::GetFirstIndent () const

StyledTextIOWriter::SrcStream::GetHidableTextRuns [public]

DiscontiguousRun < bool > StyledTextIOWriter::SrcStream::GetHidableTextRuns () const

StyledTextIOWriter::SrcStream::GetJustification [public]

Led_Justification StyledTextIOWriter::SrcStream::GetJustification () const

StyledTextIOWriter::SrcStream::GetLineSpacing [public]

Led_LineSpacing StyledTextIOWriter::SrcStream::GetLineSpacing () const

StyledTextIOWriter::SrcStream::GetListStyleInfo [public]

void StyledTextIOWriter::SrcStream::GetListStyleInfo (ListStyle* listStyle, unsigned char* indentLevel) const

StyledTextIOWriter::SrcStream::GetMargins [public]

void StyledTextIOWriter::SrcStream::GetMargins (Led_TWIPS* lhs, Led_TWIPS* rhs) const

StyledTextIOWriter::SrcStream::GetSoftLineBreakCharacter [public]

Led_tChar StyledTextIOWriter::SrcStream::GetSoftLineBreakCharacter () const

Returns the special character which should be treated (in RTF output) as the SOFT-RETURN line break character (in RTF \line).

StyledTextIOWriter::SrcStream::GetSpaceAfter [public]

Led_TWIPS StyledTextIOWriter::SrcStream::GetSpaceAfter () const

StyledTextIOWriter::SrcStream::GetSpaceBefore [public]

Led_TWIPS StyledTextIOWriter::SrcStream::GetSpaceBefore () const

StyledTextIOWriter::SrcStream::GetStandardTabStopList [public]

TextImager::StandardTabStopList StyledTextIOWriter::SrcStream::GetStandardTabStopList () const

StyledTextIOWriter::SrcStream::GetStyleInfo [public]

virtual vector < StandardStyledTextImager::InfoSummaryRecord >

StyledTextIOWriter::SrcStream::GetTotalTextLength [public]

virtual size_t GetTotalTextLength () const = 0;

Total # of tChars

StyledTextIOWriter::SrcStream::current_offset [public]

virtual size_t current_offset () const = 0;

current seekPos

StyledTextIOWriter::SrcStream::readNTChars [public]

virtual size_t readNTChars (Led_tChar* intoBuf, size_t maxTChars) = 0;

readNTChars can retun less than maxTChars before end of buffer, only to make us end on even mbyte char boundary.

StyledTextIOWriter::SrcStream::seek_to [public]

virtual void seek_to (size_t to) = 0;

'to' past end just pins one past end of buffer


Class: StyledTextIOWriterSinkStream_FileDescriptor [public]

Base Classes: StyledTextIOWriter::SinkStream
Description:

Class: StyledTextIOWriterSinkStream_Memory [public]

Base Classes: StyledTextIOWriter::SinkStream
Description:

Return to Led Page Return to Led ClassLib Documentation Index Return to Led Reference Manual Index
Last Updated 2001-10-20