Subject: Re: DOC: File Import/Export
From: Frodo Looijaard (frodol@dds.nl)
Date: Fri Jan 19 2001 - 15:31:06 CST
Dom Lachowicz wrote:
>
> Hi everyone. This is something I did at the beginning of winter break. I'm
> looking for comments/suggestions/additions to this doc before I commit it.
> Please send me comments and diff's.
Current CVS nor the 20010111 CVS can read it :-(. A debug build for
current CVS renders:
DEBUG: Setting field type desc for type 1, desc=Date and Time
DEBUG: Setting field type desc for type 2, desc=Numbers
DEBUG: Setting field type desc for type 3, desc=Piece Table
DEBUG: Setting field desc for field time, desc=Current time
DEBUG: Setting field desc for field page_number, desc=Page number
DEBUG: Setting field desc for field page_count, desc=Number of pages
DEBUG: Setting field desc for field list_label, desc=List Label
DEBUG: Setting field desc for field test, desc=Kevins Test
DEBUG: Setting field desc for field martin_test, desc=Martins Test
DEBUG: AP_UnixFrame::initializeDEBUG: EV_UnixMenu::synthesizeMenu
DEBUG: AP_UnixFrame::toggleBar 0, 1
DEBUG: AP_UnixFrame::toggleBar 1, 1
DEBUG: AP_UnixFrame::toggleBar 2, 1
DEBUG: Unknown tag [comment]
DEBUG: Unknown end tag [comment]
[Repeat last two messages many times]
DEBUG: Unknown tag [comment]
DEBUG: Unknown end tag [comment]
DEBUG: setDontChangeInsPoint: No strux in document!!
**** (1) Assert ****
**** (1) UT_SHOULD_NOT_HAPPEN at pd_Document.cpp:942 ****
**** (1) Continue ? (y/n) [y] : y
DEBUG: allowChangeInsPoint: No strux in document!!
**** (2) Assert ****
**** (2) UT_SHOULD_NOT_HAPPEN at pd_Document.cpp:975 ****
**** (2) Continue ? (y/n) [y] : y
DEBUG: fp_PageSize::Set("Letter")
DEBUG: FL_DocLayout::_toggleAutoSpell (UT_TRUE)
DEBUG: FL_DocLayout::setPendingSmartQuote(0, 0)
DEBUG: FL_DocLayout::_toggleAutoSmartQuotes(UT_TRUE)
DEBUG: Oh no - we just segfaulted!
DEBUG: File saved.
Aborted
Fortunately, a `sed 's,<[^>]*>,,g' impexp.abw' gives me enough to
read it. Though incomplete, it is certainly an enhancement from
the previous documentation, if only because it is more up-to-date.
Some comments:
* For the importer, you will need to declare also a constructor
and destructor, and override the function pasteFromBuffer (because
it is a pure virtual function). The last just needs to contain
UT_ASSERT(UT_NOT_IMPLEMENTED) (it confused me for some time what
this function was meant to do).
* You do not list return types when you enumerate the functions
to define.
* RecognizeContents may be trivial, but can be somewhat hard to do.
Perhaps you should say somewhere that, at the moment, the
file extension is checked first, and that RecognizeContents is
only used if no known extension (or no extension at all) is found.
* What would really have helped me, was a small pointer about
the use of UT_Mbtowc and the general steps to go from 'just a
character' to wchar_t and then UT_UCSChar (and the reverse
steps in the exporter). But this may belong somewhere else.
* Could you add a very small remark that the array you feed to
appendFmt and friends can contain other entries for other
XML attributes and their values?
Some more text for section 5 (export) (please edit!):
The main function you must implement should be marked as protected:
UT_Error _writeDocument(void);
Often, no real work is done in this function. Instead, you declare
a 'listener' to traverse the document. While you are doing this,
you can write the resulting output directly to file or you can
build an intermediate data-structure and write it at the end of
the _writeDocument function.
There are special write methods in (objects derived from) the
IE_Exp object that you should use to write to the file. You can
assume the file has been opened when you enter _writeDocument,
and it will be closed automatically after leaving _writeDocument.
6. Using a listener
A listener is attached to (parts of) a document and is signaled
whenever (that part of) the document changes. In case of the
exporter, we keep it very simple. Before we begin, we derive
a new object type from PL_Listener. We will have to override
the following methods:
UT_Bool populate(PL_StruxFmtHandle sfh, const PX_ChangeRecord * pcr);
UT_Bool populateStrux(PL_StruxDocHandle sdh, const PX_ChangeRecord * pcr, PL_StruxFmtHandle * psfh);
UT_Bool change(PL_StruxFmtHandle sfh, const PX_ChangeRecord * pcr);
UT_Bool insertStrux(PL_StruxFmtHandle sfh, const PX_ChangeRecord * pcr, PL_StruxDocHandle sdh, PL_ListenerId lid, void (* pfnBindHandles) (PL_StruxDocHandle sdhNew, PL_ListenerId lid, PL_StruxFmtHandle sfhNew));
UT_Bool signal(UT_uint32 iSignal);
Method populate is called whenever a span, object or format mark is
encountered. A span is some text with attributes; [WHAT ARE OBJECTS
AND FORMAT MARKS EXACTLY?].
Method populateStrux is called whenever a new block (paragraph) or
section is started.
Methods change, insertStrux and signal are never called in this context;
you can use UT_ASSERT to emphasize this and return UT_FALSE.
We define the listener in _writeDocument and attach it to the current
document through its constructor. Then we call tellListener which makes
it traverse the complete document and call its populate and populateStrux
methods for all structures within the document.
-- Frodo Looijaard <frodol@dds.nl> PGP key and more: http://huizen.dds.nl/~frodol Defenestration n. (formal or joc.): The act of removing Windows from your computer in disgust, usually followed by the installation of Linux or some other Unix-like operating system.
This archive was generated by hypermail 2b25 : Fri Jan 19 2001 - 15:31:56 CST