nyctergatis.com

Contact

Projects
Sysquake Remote Live
NME
PDF
Hike
Sudoku
GifBuilder
jpeglib for Palm OS
MySQL Client
Cross-GCC for Mac OS

NMEStyle.h File Reference


Detailed Description

Hooks to collect style information separately.

Author:
Yves Piguet. Copyright 2007-2008, Yves Piguet

Introduction

To display text with NME markup, there are two possibilities:
  • Convert NME input to some other markup which can be displayed directly, such as HTML, XML or RTF. This requires only a call to NMEProcess, maybe with custom NMEOutputFormat. For example, HTML could be used with a WebBrowser ActiveX control in Windows, or RTF with replaceCharactersInRange:withRTF: in Cocoa (Mac OS X).
  • Convert NME to text, collecting information about style separately, and apply this style information to spans of text.

NMEStyle offers support for this latter one. The NMEOutputFormat should produce pure text with end-of-line conventions appropriate for the platform, typically without wordwrap.

Usage

The code sample below is reduced to the minimum. See NME.h to see how memory allocation can be handled.

    #include "NME.h"
    #include "NMEStyle.h"

    NMEText input;
    NMEInt inputLength;
    (read source of length inputLength into input)
    NMEInt size = ...; // buffer size, typically initialized to 2x inputLength
    NMEText buf;
    buf = malloc(size);
    NMEText output;
    NMEInt outputLength;
    NMEErr err;
    for (;;)
    {
        err = NMEProcess(input, inputLength,
            buf, size,
            kNMEProcessOptDefault, "\n", &NMEOutputFormatHTML, 0,
            &output, &outputLength);
        if (err == kNMEErrNotEnoughMemory)  // unlikely
        {
            (increase size)
            (realloc buf)
        }
        else
            break;
    }
    if (err == kNMEErrOk)
        (write outputLength first bytes of output[])
    else
        (handle error)
    free(buf);

Definition in file NMEStyle.h.

#include "NME.h"

Go to the source code of this file.


Data Structures

struct  NMEStyleSpan
 Style span. More...
struct  NMEStyleTable
 Table of style spans. More...

Enumerations

enum  { kNMEErrStyleTableTooSmall = kNMEErr1stNMEOpt }
 Error codes.
enum  NMEStyleEnum {
  kNMEStyleCharPlain = 0, kNMEStyleCharBold, kNMEStyleCharItalic, kNMEStyleCharUnderline,
  kNMEStyleCharSuperscript, kNMEStyleCharSubscript, kNMEStyleCharMonospace, kNMEStyleCharLink,
  kNMEStyleCharImage, kNMEStyleCharDT, kNMEStyleCharTH, kNMEStyleParPlain,
  kNMEStyleParHeading, kNMEStyleParTable, kNMEStyleParUL, kNMEStyleParOL,
  kNMEStyleParDL, kNMEStyleParDT, kNMEStyleParIndentedPar, kNMEStyleCount
}
 Style. More...

Functions

void NMEStyleInit (NMEStyleTable *table, NMEInt size, NMEBoolean convertOffsetsToUnicode)
 Initialize NMEStyleTable.
NMEErr NMEStyleSpanHook (NMEInt level, NMEInt item, NMEBoolean enter, NMEConstText markup, NMEInt srcIndex, NMEContext *context, void *data)
 Process hook for storing styles in a table.

Variables

NMEOutputFormat const NMEOutputFormatBasicText
 Format strings for basic text output, suitable for separate style.

Enumeration Type Documentation

Style.

Enumerator:
kNMEStyleCharPlain  plain (not used in table)
kNMEStyleCharBold  bold
kNMEStyleCharItalic  italic
kNMEStyleCharUnderline  underline
kNMEStyleCharSuperscript  superscript
kNMEStyleCharSubscript  subscript
kNMEStyleCharMonospace  monospace
kNMEStyleCharLink  hypertext link
kNMEStyleCharImage  image
kNMEStyleCharDT  definition list title
kNMEStyleCharTH  table heading
kNMEStyleParPlain  plain paragraph
kNMEStyleParHeading  heading of any level
kNMEStyleParTable  table row
kNMEStyleCount  number of styles

Definition at line 77 of file NMEStyle.h.


Function Documentation

void NMEStyleInit ( NMEStyleTable table,
NMEInt  size,
NMEBoolean  convertOffsetsToUnicode 
)

Initialize NMEStyleTable.

Parameters:
[out] table table of style spans
[in] size size of table in bytes
[in] convertOffsetsToUnicode TRUE if original text is in UTF-8 and span locations in table must be converted to values for UCS-16 text (16-bit unicode), FALSE if span locations in table are in bytes (independant from the chararcter encoding)

Definition at line 57 of file NMEStyle.c.

NMEErr NMEStyleSpanHook ( NMEInt  level,
NMEInt  item,
NMEBoolean  enter,
NMEConstText  markup,
NMEInt  srcIndex,
NMEContext context,
void *  data 
)

Process hook for storing styles in a table.

Parameters:
[in] level heading or list level (1 = topmost)
[in] item list item or heading counter
[in] enter TRUE when entering construct, FALSE when exiting
[in] markup null-terminated string for initial markup ("p" for par, "*" for unnumbered list of any level, "//" for italic, "{{{" for preformatted)
[in] srcIndex current index in source code
[in,out] context current context
[in,out] data table of styles
Returns:
error code (kNMEErrOk for success)

Definition at line 118 of file NMEStyle.c.

Generated by Doxygen.
Copyright 2007-2008, Yves Piguet.
All rights reserved.