|
Hooks to collect style information separately.
More...
Go to the source code of this file.
Data Structures |
struct | NMEStyleSpan |
| Style span. More...
|
struct | NMEStyleTable |
| Table of style spans. More...
|
Typedefs |
typedef enum NMEStyleEnum | NMEStyleEnum |
| Style.
|
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, NMEInt srcLineNumber, 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.
|
Detailed Description
Hooks to collect style information separately.
- Author:
- Yves Piguet.
- Copyright:
- 2007-2013, 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 = ...;
NMEText buf;
buf = malloc(size);
NMEText output;
NMEInt outputLength, outputLengthUCS16;
NMEErr err;
NMEOutputFormat f;
f = NMEOutputFormatBasicText;
f.spanHookFun = NMEStyleSpanHook;
f.parHookFun = NMEStyleSpanHook;
f.hookData = malloc(size);
NMEStyleInit((NMEStyleTable *)f.hookData, bufSize, TRUE);
for (;;)
{
err = NMEProcess(input, inputLength,
buf, size,
kNMEProcessOptDefault, "\n", &f, 0,
&output, &outputLength, &outputLengthUCS16);
if (err == kNMEErrNotEnoughMemory
|| || err == kNMEErrStyleTableTooSmall)
{
(increase size)
(realloc buf and f.hookData)
}
else
break;
}
if (err == kNMEErrOk)
{
(apply styles in (NMEStyleTable *)f.hookData)
(write outputLength first bytes of output[])
}
else
(handle error)
free(buf);
free(f.hookData);
Definition in file NMEStyle.h.
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 91 of file NMEStyle.h.
Function Documentation
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 59 of file NMEStyle.c.
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] | srcLineNumber | current line number in source code |
[in,out] | context | current context |
[in,out] | data | table of styles |
- Returns:
- error code (kNMEErrOk for success)
Definition at line 120 of file NMEStyle.c.
|
Generated by Doxygen.
Copyright 2007-2013, Yves Piguet.
All rights reserved.
|
|