<!-- =====================================================================  -->
<!-- This file is an AbiWord document.                                      -->
<!-- AbiWord is a free, Open Source word processor.                         -->
<!-- You may obtain more information about AbiWord at www.abisource.com     -->
<!-- You should not edit this file by hand.                                 -->
<!-- =====================================================================  -->

<!--         Build_ID          = freebird-jeff -->
<!--         Build_Options     = JavaScript:Off Debug:On -->
<!--         Build_Target      = Linux_2.0.33_i386_DBG -->
<!--         Build_CompileTime = 20:01:27 -->
<!--         Build_CompileDate = Mar  9 1999 -->

<awml>
<section>
<p><c PROPS="font-family:Courier New; font-size:11pt">$Id: AbiWord_FileImport.abw,v 1.1 1999/03/10 06:39:05 jeff Exp $</c></p>
<p></p>
<p PROPS="text-align:center"><c PROPS="font-size:24pt; font-weight:bold">AbiSource File Import</c></p>
<p PROPS="text-align:center">Version 1.0</p>
<p PROPS="text-align:center">Copyright (C) 1999 AbiSource, Inc., All Rights Reserved.</p>
<p PROPS="text-align:center"></p>
<p PROPS="text-align:center">Jeff Hostetler</p>
<p PROPS="text-align:center"><c PROPS="font-family:Courier New">jeff@abisource.com</c></p>
<p PROPS="text-align:center">AbiSource, Inc.</p>
<p PROPS="text-align:center">$Date: 1999/03/10 06:39:05 $</p>
<p></p>
<p><c PROPS="font-weight:bold">1.  Introduction</c></p>
<p></p>
<p>AbiWord can import documents in several different file formats.  This document provides an overview of the import mechanism and instructions for adding support for a new format.</p>
<p></p>
<p><c PROPS="font-weight:bold">2.  class IE_Imp</c></p>
<p></p>
<p>The code for our current set of importers can be found in abi/src/wp/impexp/xp.</p>
<p></p>
<p>Class IE_Imp defines the base class for all importers.  All file importers are derived from this class.</p>
<p></p>
<p>Class IE_Imp also defines some static tables and methods which the actual file-open and file-open-dialog code will use.  This includes code to enumerate through the set of derived classes and to instantiate a specific derived class by name.</p>
<p></p>
<p><c PROPS="font-weight:bold">3.  Adding a New File Type</c></p>
<p></p>
<p>Here are the steps to add support for a new file type:</p>
<p></p>
<p PROPS="margin-left:0.5000in; text-indent:-0.5000in">[1]	In <c PROPS="font-family:Courier New">abi/src/wp/impexp/xp/ie_Imp.cpp</c>: add a <c PROPS="font-family:Courier New">DeclareImporter()</c> entry in the <c PROPS="font-family:Courier New">s_impTable[]</c>.</p>
<p PROPS="margin-left:0.5000in; text-indent:-0.5000in"></p>
<p PROPS="margin-left:0.5000in; text-indent:0.0000in">This table defines the enumeration order for things like the suffix list in the FileOpen and FileSaveAs dialogs, so watch where you add the entry.</p>
<p PROPS="margin-left:0.5000in; text-indent:0.0000in"></p>
<p PROPS="margin-left:0.5000in; text-indent:-0.5000in">[2]	Currently the code in IE_Imp::constructImporter() is quite stupid.  It determines the type of document by a simple test of the file's suffix.  We hope to improve this later, but for now that's how it works.  Therefore, you will need to choose a unique suffix for your importer.</p>
<p PROPS="margin-left:0.5000in; text-indent:-0.5000in"></p>
<p PROPS="margin-left:0.5000in; text-indent:-0.5000in">[3]	Clone one of the existing importers and start hacking.</p>
<p PROPS="margin-left:0.5000in; text-indent:-0.5000in"></p>
<p PROPS="margin-left:0.5000in; text-indent:-0.5000in">[4]	Each importer must define 3 static methods to allow IE_Imp to properly enumerate them and delegate work to them:  RecognizeSuffix(), StaticConstructor(), and GetDlgLabels().  The first is used in the suffix guessing described in [2].  The second is used to instantiate an instance of the importer.  And the third is used by the FileOpen and FileSaveAs dialogs to populate the FileType combo box (on the platforms that have one).</p>
<p PROPS="margin-left:0.5000in; text-indent:-0.5000in"></p>
<p PROPS="margin-left:0.5000in; text-indent:-0.5000in">[5]	As a first step in creating your importer, I recommend that you start by just  extracting the text of the document without worrying about formatting.  The most trivial document contains one section, one block (paragraph), and some content (one or more spans).  So you should be able to get something on the screen with nothing more than this:</p>
<p PROPS="margin-left:0.5000in; text-indent:-0.5000in"></p>
<p><c PROPS="font-family:Courier New">		m_pDocument-&gt;appendStrux(PTX_Section,NULL);</c></p>
<p><c PROPS="font-family:Courier New">		m_pDocument-&gt;appendStrux(PTX_Block,NULL);</c></p>
<p><c PROPS="font-family:Courier New">		m_pDocument-&gt;appendSpan(data,length);</c></p>
<p><c PROPS="font-family:Courier New">		m_pDocument-&gt;appendSpan(data,length);</c></p>
<p><c PROPS="font-family:Courier New">		...</c></p>
<p></p>
<p PROPS="margin-left:0.5000in">You can make as many calls to appendSpan() within a block as you need.</p>
<p></p>
<p PROPS="margin-left:0.5000in; text-indent:-0.5000in">[6]	Once you get that working, you can start adding section, block and span formatting attributes using the second argument of appendStrux() and the appendFmt() method.  These consist of a series of CSS2-like name-value pairs.  See AbiWord_DocumentFormat.abw and the source for the other importers for details.</p>
<p></p>
<p></p>
</section>
</awml>
