示例#1
0
UT_Error IE_Imp_WordPerfect::_appendSection(int numColumns, const float marginLeft, const float marginRight)
{
	UT_DEBUGMSG(("AbiWordPerfect: Appending section\n"));
	
	UT_String myProps("") ;
	UT_LocaleTransactor lt(LC_NUMERIC, "C");
	myProps += UT_String_sprintf("columns:%d; page-margin-left:%.4fin; page-margin-right:%.4fin", numColumns, marginLeft, marginRight);

	if(m_bInSection && m_bRequireBlock) // AbiWord will hang on an empty <section>
	{
		X_CheckDocumentError(appendStrux(PTX_Block,PP_NOPROPS));
	}

	const PP_PropertyVector propsArray = {
		"props", myProps.c_str()
	};
	X_CheckDocumentError(appendStrux(PTX_Section, propsArray));

	m_bInSection = true;
	m_bRequireBlock = true;

	m_bSectionChanged = false;

	return UT_OK;
}
UT_Error IE_Imp_Psion::processHeaderFooter(const psiconv_page_layout_section layout,
                                           bool with_header, bool with_footer)
{
	const gchar* propsArray[5];
	UT_Error res;
	
	// Header
	if (with_header) {
		propsArray[0] = (const gchar *) "id";
		propsArray[1] = (const gchar *) "1";
		propsArray[2] = (const gchar *) "type";
		propsArray[3] = (const gchar *) "header";
		propsArray[4] = NULL;
		if (!appendStrux(PTX_SectionHdrFtr,propsArray))
			return UT_IE_IMPORTERROR;
		if ((res = readParagraphs(layout->header->text->paragraphs,NULL)))
			return res;
	}
	
	// Footer
	if (with_footer) {
		propsArray[0] = (const gchar *) "id";
		propsArray[1] = (const gchar *) "2";
		propsArray[2] = (const gchar *) "type";
		propsArray[3] = (const gchar *) "footer";
		propsArray[4] = NULL;
		if (!appendStrux(PTX_SectionHdrFtr,propsArray))
			return UT_IE_IMPORTERROR;
		if ((res = readParagraphs(layout->footer->text->paragraphs,NULL)))
			return res;
	}
	return res;
}
void IE_Imp_WordPerfect::openEndnote(const WPXPropertyList & /*propList*/)
{
	if (m_bHdrFtrOpenCount) return; // HACK
	const gchar** propsArray = NULL;
	
	UT_String endnoteId;
	UT_String_sprintf(endnoteId,"%i",UT_rand());	
	
	propsArray = static_cast<const gchar **>(UT_calloc(7, sizeof(gchar *)));
	propsArray [0] = "type";
	propsArray [1] = "endnote_ref";
	propsArray [2] = "endnote-id";
	propsArray [3] = endnoteId.c_str();
	propsArray [4] = NULL;
	propsArray [5] = NULL;
	propsArray [6] = NULL;
	X_CheckDocumentError(appendObject(PTO_Field, propsArray));

	const gchar * attribs[3] ={"endnote-id", endnoteId.c_str(), NULL};
	X_CheckDocumentError(appendStrux(PTX_SectionEndnote,attribs));
	
	X_CheckDocumentError(appendStrux(PTX_Block,NULL));
	m_bRequireBlock = false;

	propsArray = static_cast<const gchar **>(UT_calloc(7, sizeof(gchar *)));
	propsArray [0] = "type";
	propsArray [1] = "endnote_anchor";
	propsArray [2] = "endnote-id";
	propsArray [3] = endnoteId.c_str();
	propsArray [4] = NULL;
	propsArray [5] = NULL;
	propsArray [6] = NULL;
	X_CheckDocumentError(appendObject(PTO_Field, propsArray));
}
示例#4
0
void IE_Imp_WordPerfect::openFootnote(const librevenge::RVNGPropertyList & /*propList*/)
{
	if (m_bHdrFtrOpenCount) return; // HACK

	if (!m_bInSection)
	{
		X_CheckDocumentError(appendStrux(PTX_Section, PP_NOPROPS));
		X_CheckDocumentError(appendStrux(PTX_Block,PP_NOPROPS));
		m_bInSection = true;
	}

	std::string footnoteId = UT_std_string_sprintf("%i", UT_rand());

	PP_PropertyVector propsArray = {
		"type",	"footnote_ref",
		"footnote-id", footnoteId
	};
	X_CheckDocumentError(appendObject(PTO_Field, propsArray));

	const PP_PropertyVector attribs = {
		"footnote-id", footnoteId
	};
	X_CheckDocumentError(appendStrux(PTX_SectionFootnote, attribs));

	X_CheckDocumentError(appendStrux(PTX_Block, PP_NOPROPS));
	m_bRequireBlock = false;

	// just change the type.
	propsArray[1] = "footnote_anchor";
	X_CheckDocumentError(appendObject(PTO_Field, propsArray));
}
示例#5
0
UT_Error IE_Imp_Psion::processHeaderFooter(const psiconv_page_layout_section layout,
                                           bool with_header, bool with_footer)
{
	UT_Error res;

	// Header
	if (with_header) {
		const PP_PropertyVector propsArray = {
			"id", "1",
			"type", "header"
		};
		if (!appendStrux(PTX_SectionHdrFtr,propsArray)) {
			return UT_IE_IMPORTERROR;
		}
		if ((res = readParagraphs(layout->header->text->paragraphs,NULL))) {
			return res;
		}
	}

	// Footer
	if (with_footer) {
		const PP_PropertyVector propsArray = {
			"id", "2",
			"type", "footer"
		};
		if (!appendStrux(PTX_SectionHdrFtr,propsArray)) {
			return UT_IE_IMPORTERROR;
		}
		if ((res = readParagraphs(layout->footer->text->paragraphs,NULL))) {
			return res;
		}
	}
	return res;
}
UT_Error IE_Imp_Hancom::_loadFile(GsfInput * input) {
  mDoc = GSF_INFILE(gsf_infile_msole_new (input, NULL));

  if (!mDoc)
    return UT_IE_BOGUSDOCUMENT;

  GsfInput *textStream = gsf_infile_child_by_name(mDoc, "/PrvText");
  if (!textStream)
    return UT_IE_BOGUSDOCUMENT;

  size_t len = gsf_input_size(textStream);

  UT_DEBUGMSG(("HANCOM: Text length = %zd bytes\n", len));
  unsigned char* buf = new unsigned char[len];

  if (!buf) {
    g_object_unref (G_OBJECT (textStream));
    return UT_IE_NOMEMORY;
  }

  gsf_input_read(textStream, len, buf);
  g_object_unref (G_OBJECT (textStream));

  UT_uint32 length;
  UT_UCS4Char* text = reinterpret_cast<UT_UCS4Char*>(UT_convert((const char *)buf, len, "UCS-2LE", 
								UCS_INTERNAL, NULL, &length));
  delete[] buf;
  if (!text)
    return UT_IE_NOMEMORY;

  UT_DEBUGMSG(("HANCOM: Text successfully converted.\n"));

  if (!appendStrux(PTX_Section, NULL)) {
    FREEP(text);
    return UT_IE_NOMEMORY;
  }
  
  if (!appendStrux(PTX_Block, NULL)) {
    FREEP(text);
    return UT_IE_NOMEMORY;
  }
  
  if (!appendSpan(text, length/4)) {
    FREEP(text);
    return UT_IE_NOMEMORY;
  }

  FREEP(text);
  return UT_OK;
}
示例#7
0
void IE_Imp_WordPerfect::closeTable()
{
	if (m_bHdrFtrOpenCount) return; // HACK
	UT_DEBUGMSG(("AbiWordPerfect: Closing table\n"));
	
	if (m_bInCell)
	{
		X_CheckDocumentError(appendStrux(PTX_EndCell, PP_NOPROPS));
	}
	X_CheckDocumentError(appendStrux(PTX_EndTable, PP_NOPROPS));
	m_bInCell = false;
	
	// we need to open a new paragraph after a table, since libwpd does NOT do it
	// FIXME: NEED TO PASS THE CURRENT PROPERTIES INSTEAD OF NULL
	// NOTE: THIS SUCKS.........
	X_CheckDocumentError(appendStrux(PTX_Block, PP_NOPROPS));
	m_bRequireBlock = false;
}
/*!
  Write header to document

 Writes the minimum needed Section and Block before we begin import
 */
UT_Error IE_Imp_Text::_writeHeader(GsfInput * /* fp */)
{
	// text gets applied in the Normal style
	const gchar * propsArray[3];
	propsArray[0] = "style";
	propsArray[1] = "Normal";
	propsArray[2] = 0;

	X_ReturnNoMemIfError(appendStrux(PTX_Section, NULL));
	X_ReturnNoMemIfError(appendStrux(PTX_Block, static_cast<const gchar**>(&propsArray[0])));

	pf_Frag * pf = getDoc()->getPieceTable()->getFragments().getLast();
	UT_return_val_if_fail( pf->getType() == pf_Frag::PFT_Strux, UT_ERROR);
	m_pBlock = (pf_Frag_Strux *) pf;
	UT_return_val_if_fail( m_pBlock->getStruxType() == PTX_Block, UT_ERROR );
  
	return UT_OK;
}
/*!
  Insert a Block into the document

 Uses appropriate function for clipboard or file
 */
bool IE_Imp_Text::_insertBlock()
{
	bool ret = false;
	m_bBlockDirectionPending = true;
	m_bFirstBlockData = true;
	
	if (isClipboard ()) // intentional - don't append style
						// information
	{		
		ret = appendStrux(PTX_Block, NULL);
	}
	else
	{
	    // text gets applied in the Normal style
	    const gchar * propsArray[3];
	    propsArray[0] = "style";
	    propsArray[1] = "Normal";
	    propsArray[2] = 0;

	    ret = appendStrux(PTX_Block, static_cast<const gchar **>(&propsArray[0]));
	}
	if(!isPasting())
	{
		pf_Frag * pf = getDoc()->getPieceTable()->getFragments().getLast();
		UT_return_val_if_fail( pf->getType() == pf_Frag::PFT_Strux, false);
		m_pBlock = (pf_Frag_Strux *) pf;
		UT_return_val_if_fail( m_pBlock->getStruxType() == PTX_Block, false);
	}
	else
	{
		PL_StruxDocHandle sdh = NULL;
		if(getDoc()->getStruxOfTypeFromPosition(getDocPos(), PTX_Block,&sdh))
		{
			m_pBlock = static_cast<pf_Frag_Strux *>(const_cast<void *>(sdh));
		}
		else
		{
			m_pBlock = NULL;
		}
	}
	return ret;
}
示例#10
0
void IE_Imp_WordPerfect::openTableRow(const librevenge::RVNGPropertyList & /*propList*/)
{
	if (m_bHdrFtrOpenCount) return; // HACK
	UT_DEBUGMSG(("AbiWordPerfect: openRow\n"));
	if (m_bInCell)
	{
		X_CheckDocumentError(appendStrux(PTX_EndCell, PP_NOPROPS));
	}

	m_bInCell = false;
}
示例#11
0
void IE_Imp_WordPerfect::openTable(const librevenge::RVNGPropertyList &propList)
{
	if (m_bHdrFtrOpenCount) return; // HACK
	// TODO: handle 'marginLeftOffset' and 'marginRightOffset'
	UT_DEBUGMSG(("AbiWordPerfect: openTable\n"));
	
	UT_String propBuffer;

	if (propList["table:align"])
	{
		// no need to support left: default behaviour

		//if (strcmp(propList["table:align"]->getStr().cstr(), "right"))
		// abiword does not support this I think
		//if (strcmp(propList["table:align"]->getStr().cstr(), "center"))
		// abiword does not support this I think
		//if (strcmp(propList["table:align"]->getStr().cstr(), "margins"))
		// abiword does not support this I think
		if (strcmp(propList["table:align"]->getStr().cstr(), "margins"))
		{
			if (propList["fo:margin-left"])
				UT_String_sprintf(propBuffer, "table-column-leftpos:%s; ", propList["fo:margin-left"]->getStr().cstr());
		}
	}
	
	const librevenge::RVNGPropertyListVector *columns = propList.child("librevenge:table-columns");
	if (columns)
	{
		propBuffer += "table-column-props:";
		librevenge::RVNGPropertyListVector::Iter i(*columns);
		for (i.rewind(); i.next();)
		{
			UT_String tmpBuffer;
			if (i()["style:column-width"])
				UT_String_sprintf(tmpBuffer, "%s/", i()["style:column-width"]->getStr().cstr());
			propBuffer += tmpBuffer;
		}
	}

	const PP_PropertyVector propsArray = {
		"props", propBuffer.c_str()
	};
	X_CheckDocumentError(appendStrux(PTX_SectionTable, propsArray));
}
UT_Error IE_Imp_PalmDoc::_parseFile(GsfInput * pdfp)
{
	UT_GrowBuf gbBlock(1024);
	bool bEatLF = false;
	bool bEmptyFile = true;
	UT_UCSChar c;
	UT_UCS4Char wc;

	pdb_header	header;
	doc_record0	rec0;
	bool		bCompressed = false;
	int		num_records, rec_num;
	DWord		file_size, offset;

	gsf_input_read( pdfp, PDB_HEADER_SIZE, (guint8*)&header);
	if (strncmp( header.type,    DOC_TYPE,    sizeof(header.type) ) ||
	    strncmp( header.creator, DOC_CREATOR, sizeof(header.creator) ))
        {
		UT_DEBUGMSG(("This is not a DOC file!\n"));

		// Create an empty paragraph.
		X_ReturnNoMemIfError(appendStrux(PTX_Block, NULL));
		return UT_OK;
	}

	num_records = _swap_Word( header.numRecords ) - 1;

	gsf_input_seek( pdfp, PDB_HEADER_SIZE, G_SEEK_SET );
	GET_DWord( pdfp, offset );
	gsf_input_seek( pdfp, offset, G_SEEK_SET );
	gsf_input_read( pdfp, sizeof(rec0), (guint8*)&rec0);

	if ( _swap_Word( rec0.version ) == 2 )
		bCompressed = true;

	gsf_input_seek( pdfp, 0, G_SEEK_END );
	file_size = gsf_input_tell( pdfp );

	for (rec_num = 1; rec_num <= num_records; ++rec_num )
	{
		DWord next_offset;

		gsf_input_seek( pdfp, PDB_HEADER_SIZE + PDB_RECORD_HEADER_SIZE * rec_num, G_SEEK_SET);
		GET_DWord( pdfp, offset );
		if( rec_num < num_records )
		{
			gsf_input_seek( pdfp, PDB_HEADER_SIZE + PDB_RECORD_HEADER_SIZE * (rec_num + 1), G_SEEK_SET);
			GET_DWord( pdfp, next_offset );
		}
		else
			next_offset = file_size;

		gsf_input_seek( pdfp, offset, G_SEEK_SET );

		// be overly cautious here
		_zero_fill (m_buf->buf, BUFFER_SIZE);
		gsf_input_read(pdfp, next_offset - offset, m_buf->buf);
		m_buf->position = next_offset - offset;

		if ( bCompressed )
			_uncompress( m_buf );

		m_buf->position = 0;

		while ( (m_buf->position) < (m_buf->len) )
		{
		  // don't copy over null chars
		        if (m_buf->buf[m_buf->position] == '\0')
			  {
			    ++m_buf->position;
			    continue;
			  }
			if( !m_Mbtowc.mbtowc( wc, m_buf->buf[m_buf->position] ) )
		 	   continue;
			c = static_cast<UT_UCSChar>(wc);
			switch (c)
			{
			case static_cast<UT_UCSChar>('\r'):
			case static_cast<UT_UCSChar>('\n'):
			
				if ((c == static_cast<UT_UCSChar>('\n')) && bEatLF)
				{
					bEatLF = false;
					break;
				}

				if (c == static_cast<UT_UCSChar>('\r'))
				{
					bEatLF = true;
				}
		
				// we interprete either CRLF, CR, or LF as a paragraph break.
		
				// start a paragraph and emit any text that we
				// have accumulated.
				X_ReturnNoMemIfError(appendStrux(PTX_Block, NULL));
				bEmptyFile = false;
				if (gbBlock.getLength() > 0)
				{
					X_ReturnNoMemIfError(appendSpan(reinterpret_cast<const UT_UCSChar*>(gbBlock.getPointer(0)), gbBlock.getLength()));
					gbBlock.truncate(0);
				}
				break;

			default:
				bEatLF = false;
				X_ReturnNoMemIfError(gbBlock.ins(gbBlock.getLength(),reinterpret_cast<const UT_GrowBufElement *>(&c),1));
				break;
			}

			++m_buf->position;
		} 

	}
	if (gbBlock.getLength() > 0 || bEmptyFile)
	{
		// if we have text left over (without final CR/LF),
		// or if we read an empty file,
		// create a paragraph and emit the text now.
		X_ReturnNoMemIfError(appendStrux(PTX_Block, NULL));
		if (gbBlock.getLength() > 0)
			X_ReturnNoMemIfError(appendSpan(reinterpret_cast<const UT_UCSChar *>(gbBlock.getPointer(0)), gbBlock.getLength()));
	}

	return UT_OK;
}
void IE_Imp_WordPerfect::closeFootnote()
{
	if (m_bHdrFtrOpenCount) return; // HACK
	X_CheckDocumentError(appendStrux(PTX_EndFootnote,NULL));
}
UT_Error IE_Imp_PalmDoc::_writeHeader(GsfInput * /* m_pdfp */)
{
	X_ReturnNoMemIfError(appendStrux(PTX_Section, NULL));
	return UT_OK;
}
示例#15
0
// ASSUMPTION: We assume that unordered lists will always pass a number of "0". unpredictable behaviour
// may result otherwise
void IE_Imp_WordPerfect::openListElement(const librevenge::RVNGPropertyList &propList)
{
	if (m_bHdrFtrOpenCount) return; // HACK
	UT_DEBUGMSG(("AbiWordPerfect: openListElement\n"));
	
	UT_ASSERT(m_pCurrentListDefinition); // FIXME: ABI_LISTS_IMPORT throw an exception back to libwpd, if this fails
	
	// Paragraph properties for our list element
	UT_String szListID;
	UT_String szParentID;
	UT_String szLevel;
	UT_String_sprintf(szListID,"%d",m_pCurrentListDefinition->getListID(m_iCurrentListLevel));
	if (m_iCurrentListLevel > 1) 
		UT_String_sprintf(szParentID,"%d", m_pCurrentListDefinition->getListID((m_iCurrentListLevel-1)));
	else
		UT_String_sprintf(szParentID,"0"); 
	UT_String_sprintf(szLevel,"%d", m_iCurrentListLevel);
	
	const gchar* listAttribs[PT_MAX_ATTRIBUTES*2 + 1];
	UT_uint32 attribsCount=0;
	
	listAttribs[attribsCount++] = PT_LISTID_ATTRIBUTE_NAME;
	listAttribs[attribsCount++] = szListID.c_str();
	listAttribs[attribsCount++] = PT_PARENTID_ATTRIBUTE_NAME;
	listAttribs[attribsCount++] = szParentID.c_str();
	listAttribs[attribsCount++] = PT_LEVEL_ATTRIBUTE_NAME;
	listAttribs[attribsCount++] = szLevel.c_str();
	
	// Now handle the Abi List properties
	UT_String propBuffer;
	UT_String tempBuffer;
	UT_String_sprintf(tempBuffer,"list-style:%i;", m_pCurrentListDefinition->getListType(m_iCurrentListLevel));
	propBuffer += tempBuffer;

#if 0
	// FIXME: writing the list delimiter is kind of tricky and silly (because wordperfect wants to define
	// it within the document, while abi wants to (sensibly probably) define it in the list definition)
	// (we reset it each time but only for numbered lists)
	if (listDefinition->isLevelNumbered(m_iCurrentListLevel)) 
	{  
		UT_DEBUGMSG(("WordPerfect: Appending this list delim: %s\n", m_rightListDelim.c_str()));
		listDefinition->setListRightDelimText(m_iCurrentListLevel, m_rightListDelim.c_str());
		X_CheckWordPerfectError(_updateDocumentListDefinition(listDefinition, m_iCurrentListLevel));
	}
#endif

	if (m_pCurrentListDefinition->getListType(m_iCurrentListLevel) == BULLETED_LIST)
		UT_String_sprintf(tempBuffer, "field-font:Symbol; ");
	else
		UT_String_sprintf(tempBuffer, "field-font:NULL; ");
	
	m_pCurrentListDefinition->incrementLevelNumber(m_iCurrentListLevel);
	
	propBuffer += tempBuffer;
	UT_String_sprintf(tempBuffer, "start-value:%i; ", 1);
	propBuffer += tempBuffer;

	UT_String_sprintf(tempBuffer, "margin-left:%.4fin; ", m_pCurrentListDefinition->getListLeftOffset(m_iCurrentListLevel)
					+ m_pCurrentListDefinition->getListMinLabelWidth(m_iCurrentListLevel)
					- (propList["fo:text-indent"] ? propList["fo:text-indent"]->getDouble() : 0.0f));
	propBuffer += tempBuffer;
	UT_String_sprintf(tempBuffer, "text-indent:%.4fin", - m_pCurrentListDefinition->getListMinLabelWidth(m_iCurrentListLevel)
					+ (propList["fo:text-indent"] ? propList["fo:text-indent"]->getDouble() : 0.0f));
	propBuffer += tempBuffer;

	listAttribs[attribsCount++] = PT_PROPS_ATTRIBUTE_NAME;
	listAttribs[attribsCount++] = propBuffer.c_str();
	listAttribs[attribsCount++] = NULL;

	X_CheckDocumentError(appendStrux(PTX_Block, PP_std_copyProps(listAttribs)));
	m_bRequireBlock = false;

	// hang text off of a list label
	getDoc()->appendFmtMark();
	UT_DEBUGMSG(("WordPerfect: LISTS - Appended a list tag def'n (character props)\n"));

	// append a list field label
	PP_PropertyVector fielddef = {
		"type", "list_label"
	};
	X_CheckDocumentError(appendObject(PTO_Field,fielddef));
	UT_DEBUGMSG(("WordPerfect: LISTS - Appended a field def'n\n"));

	// insert a tab
	UT_UCS4Char ucs = UCS_TAB;
	X_CheckDocumentError(appendSpan(&ucs,1));
}
示例#16
0
void IE_Imp_WordPerfect::openParagraph(const librevenge::RVNGPropertyList &propList)
{
	if (m_bHdrFtrOpenCount) return; // HACK
	UT_DEBUGMSG(("AbiWordPerfect: openParagraph()\n"));
	// for now, we always append these options
	float marginTop = 0.0f, marginBottom = 0.0f;
	float marginLeft = 0.0f, marginRight = 0.0f, textIndent = 0.0f;
	if (propList["fo:margin-top"])
	    marginTop = propList["fo:margin-top"]->getDouble();
	if (propList["fo:margin-bottom"])
	    marginBottom = propList["fo:margin-bottom"]->getDouble();
	if (propList["fo:margin-left"])
	    marginLeft = propList["fo:margin-left"]->getDouble();
	if (propList["fo:margin-right"])
	    marginRight = propList["fo:margin-right"]->getDouble();
	if (propList["fo:text-indent"])
	    textIndent = propList["fo:text-indent"]->getDouble();

	m_topMargin = marginTop;
	m_bottomMargin = marginBottom;
	m_leftMarginOffset = marginLeft;
	m_rightMarginOffset = marginRight;
	m_textIndent = textIndent;

	UT_String propBuffer;
	propBuffer += "text-align:";
	if (propList["fo:text-align"])
	{
		// AbiWord follows xsl:fo, except here, for some reason..
		if (propList["fo:text-align"]->getStr() == "end")
			propBuffer += "right";
		else
			propBuffer += propList["fo:text-align"]->getStr().cstr();
	}
	else
		propBuffer += "left";

	float lineSpacing = 1.0f;
	if (propList["fo:line-height"])
		lineSpacing = propList["fo:line-height"]->getDouble();
	
	UT_String tmpBuffer;
	UT_String_sprintf(tmpBuffer, "; margin-top:%dpt; margin-bottom:%dpt; margin-left:%.4fin; margin-right:%.4fin; text-indent:%.4fin; line-height:%.4f",
		(int)(m_topMargin*72), (int)(m_bottomMargin*72), m_leftMarginOffset, m_rightMarginOffset, m_textIndent, lineSpacing);
	propBuffer += tmpBuffer;
	
	const librevenge::RVNGPropertyListVector *tabStops = propList.child("style:tab-stops");
	
	if (tabStops && tabStops->count()) // Append the tabstop information
	{
		propBuffer += "; tabstops:";
		tmpBuffer = "";
		librevenge::RVNGPropertyListVector::Iter i(*tabStops);
		for (i.rewind(); i.next();)
		{
			propBuffer += tmpBuffer;
			if (i()["style:position"])
			{
				UT_String_sprintf(tmpBuffer, "%.4fin", i()["style:position"]->getDouble());
				propBuffer += tmpBuffer;
			}

			if (i()["style:type"])
				if (i()["style:type"]->getStr() == "right")
					propBuffer += "/R";
				else if (i()["style:type"]->getStr() == "center")
					propBuffer += "/C";
				else if (i()["style:type"]->getStr() == "char")
					propBuffer += "/D";
				else
					propBuffer += "/L";
			else // Left aligned is default
				propBuffer += "/L";

			if (i()["style:leader-text"])
				if (i()["style:leader-text"]->getStr() == "-")
					propBuffer += "2";
				else if (i()["style:leader-text"]->getStr() == "_")
					propBuffer += "3";
				else // default to dot leader if the given leader is dot or is not supported by AbiWord
					propBuffer += "1";
			else
				propBuffer += "0";

			tmpBuffer = ",";
		}
	}


	UT_DEBUGMSG(("AbiWordPerfect: Appending paragraph properties: %s\n", propBuffer.c_str()));
	const PP_PropertyVector propsArray = {
		"props", propBuffer.c_str()
	};
	X_CheckDocumentError(appendStrux(PTX_Block, propsArray));
	m_bRequireBlock = false;

	if (propList["fo:break-before"])
	{
		if (strcmp(propList["fo:break-before"]->getStr().cstr(), "page") == 0)
		{
			UT_UCS4Char ucs = UCS_FF;
			X_CheckDocumentError(appendSpan(&ucs,1));
		}
		else if (strcmp(propList["fo:break-before"]->getStr().cstr(), "column") == 0)
		{
			UT_UCS4Char ucs = UCS_VTAB;
			X_CheckDocumentError(appendSpan(&ucs,1));
		}
	}
}
示例#17
0
UT_Error IE_Imp_StarOffice::_loadFile(GsfInput * input)
{
	try {
		UT_DEBUGMSG(("SDW: Starting import\n"));
		mOle = GSF_INFILE (gsf_infile_msole_new(input, NULL));
		if (!mOle)
			return UT_IE_BOGUSDOCUMENT;

		// firstly, load metadata
		SDWDocInfo::load(mOle, getDoc());

		mDocStream = gsf_infile_child_by_name(mOle, "StarWriterDocument");
		if (!mDocStream)
			return UT_IE_BOGUSDOCUMENT;

		gsf_off_t size = gsf_input_size(mDocStream);

		if (!appendStrux(PTX_Section, PP_NOPROPS))
			return UT_IE_NOMEMORY;

		UT_DEBUGMSG(("SDW: Attempting to load DocHdr...\n"));
		mDocHdr.load(mDocStream);
		UT_DEBUGMSG(("SDW: ...success\n"));

		// Ask for and verify the password
		if (mDocHdr.cryptor) {
			if (!mDocHdr.cryptor->SetPassword(GetPassword().c_str())) {
				UT_DEBUGMSG(("SDW: Wrong password\n"));
				return UT_IE_PROTECTED;
			}
		}

		// do the actual reading
		char type;
		bool done = false;
		UT_uint32 recSize;
		while (!done) {
			if (gsf_input_tell(mDocStream) == size)
				break;
			readChar(mDocStream, type);
			gsf_off_t eor;
			readRecSize(mDocStream, recSize, &eor);

			switch (type) {
				case SWG_CONTENTS: {
					gsf_off_t flagsEnd = 0;
					UT_uint32 nNodes;
					// sw/source/core/sw3io/sw3sectn.cxx#L129
					if (mDocHdr.nVersion >= SWG_LAYFRAMES) {
						UT_uint8 flags;
						readFlagRec(mDocStream, flags, &flagsEnd);
					}
					if (mDocHdr.nVersion >= SWG_LONGIDX)
						streamRead(mDocStream, nNodes);
					else {
						if (mDocHdr.nVersion >= SWG_LAYFRAMES) {
							UT_uint16 sectidDummy;
							streamRead(mDocStream, sectidDummy);
						}
						UT_uint16 nodes16;
						streamRead(mDocStream, nodes16);
						nNodes = (UT_uint32)nodes16;
					}
					if (flagsEnd) {
						UT_ASSERT(flagsEnd >= gsf_input_tell(mDocStream));
						if (gsf_input_tell(mDocStream) != flagsEnd) {
							UT_DEBUGMSG(("SDW: have not read all flags\n"));
							if (gsf_input_seek(mDocStream, flagsEnd, G_SEEK_SET))
								return UT_IE_BOGUSDOCUMENT;
						}
					}
					bool done2 = false;
					UT_uint32 size2;
					while (!done2) {
						readChar(mDocStream, type);
						gsf_off_t eor2;
						readRecSize(mDocStream, size2, &eor2);

						switch (type) {
							case SWG_TEXTNODE: { // sw/source/core/sw3io/sw3nodes.cxx#L788
								UT_DEBUGMSG(("SDW: Found Textnode! (start at 0x%08llX end at 0x%08llX)\n", 
											 (long long)gsf_input_tell(mDocStream), 
											 (long long)eor2));
								UT_uint8 flags;
								gsf_off_t newPos;
								readFlagRec(mDocStream, flags, &newPos);
								// XXX check flags
								if (gsf_input_seek(mDocStream, newPos, G_SEEK_SET))
									return UT_IE_BOGUSDOCUMENT;

								// Read the actual text
								UT_UCS4Char* str;
								readByteString(mDocStream, str);
								UT_UCS4String textNode(str);
								free(str);
								UT_DEBUGMSG(("SDW: ...length=%zu contents are: |%s|\n", textNode.length(), textNode.utf8_str()));

								// now get the attributes
								UT_String attrs;
								UT_String pAttrs;
								UT_Vector charAttributes;
								while (gsf_input_tell(mDocStream) < eor2) {
									char attVal;
									streamRead(mDocStream, attVal);
									UT_uint32 attSize;
									gsf_off_t eoa; // end of attribute
									readRecSize(mDocStream, attSize, &eoa);
									if (attVal == SWG_ATTRIBUTE) {
										TextAttr* a = new TextAttr;
										streamRead(mDocStream, *a, eoa);
										UT_DEBUGMSG(("SDW: ...found text-sub-node, which=0x%x, ver=0x%x, start=%u, end=%u - data:%s len:%llu data is:",
													 a->which, a->ver, a->start,
													 a->end, a->data?"Yes":"No",
													 (long long unsigned)a->dataLen));
#ifdef DEBUG
										hexdump(a->data, a->dataLen);
                    putc('\n', stderr);
#endif
										charAttributes.addItem(a);
									}
									else if (attVal == SWG_ATTRSET) {
									  // bah, yet another loop
										UT_DEBUGMSG(("SDW: ...paragraph attributes found\n"));
										while (gsf_input_tell(mDocStream) < eoa) {
											// reusing attVal and attSize
											streamRead(mDocStream, attVal);
											gsf_off_t eoa2; // end of attribute
											readRecSize(mDocStream, attSize, &eoa2);
											if (attVal == SWG_ATTRIBUTE) {
												TextAttr a;
												streamRead(mDocStream, a, eoa2);
                        if (!a.attrVal.empty()) {
  												if (a.isPara)
	  												UT_String_setProperty(pAttrs, a.attrName, a.attrVal);
		  										else
			  										UT_String_setProperty(attrs, a.attrName, a.attrVal);
                        }
						UT_DEBUGMSG(("SDW: ......found paragraph attr, which=0x%x, ver=0x%x, start=%u, end=%u (string now %s) Data:%s Len=%lld Data:", a.which, a.ver, (a.startSet?a.start:0), (a.endSet?a.end:0), attrs.c_str(), (a.data ? "Yes" : "No"), (long long)a.dataLen));
#ifdef DEBUG
												hexdump(a.data, a.dataLen);
                        putc('\n', stderr);
#endif
											}
											if (gsf_input_seek(mDocStream, eoa2, G_SEEK_SET))
												return UT_IE_BOGUSDOCUMENT;
										}
									}
									else {
										UT_DEBUGMSG(("SDW: ...unknown attribute '%c' found (start=%" GSF_OFF_T_FORMAT " end=%" GSF_OFF_T_FORMAT ")\n", attVal, gsf_input_tell(mDocStream), eoa));
									}
									if (gsf_input_seek(mDocStream, eoa, G_SEEK_SET))
										return UT_IE_BOGUSDOCUMENT;
								}

								PP_PropertyVector attributes = {
									"props",
									pAttrs.c_str()
								};
								// first, insert the paragraph
								if (!appendStrux(PTX_Block, attributes))
									return UT_IE_NOMEMORY;

								UT_String pca(attrs); // character attributes for the whole paragraph
								// now insert the spans of text
								UT_uint32 len = textNode.length();
								UT_uint32 lastInsPos = 0;
								for (UT_uint32 i = 1; i < len; i++) {
									bool doInsert = false; // whether there was an attribute change
									for (UT_sint32 j = 0; j < charAttributes.getItemCount(); j++) {
										const TextAttr* a = reinterpret_cast<const TextAttr*>(charAttributes[j]);
										// clear the last attribute, if set
										if (a->endSet && a->end == (i - 1)) {
											if (a->isOff) {
												UT_String propval = UT_String_getPropVal(pca, a->attrName);
												UT_String_setProperty(attrs, a->attrName, propval);
											}
											else
												UT_String_removeProperty(attrs, a->attrName);
										}

										// now set new attribute, if needed
										if (a->startSet && a->start == (i - 1)) {
											if (a->isPara)
												UT_String_setProperty(pAttrs, a->attrName, a->attrVal);
											else if (a->isOff)
												UT_String_removeProperty(attrs, a->attrName);
											else
												UT_String_setProperty(attrs, a->attrName, a->attrVal);
										}

										// insert if this is the last character, or if there was a format change
										if ((a->endSet && a->end == i) || (a->startSet && a->start == i))
											doInsert = true;
									}
									if (doInsert || i == (len - 1)) {
										attributes[1] = attrs.c_str();
										UT_DEBUGMSG(("SDW: Going to appendFmt with %s\n", attributes[1].c_str()));
										if (!appendFmt(attributes))
											return UT_IE_NOMEMORY; /* leave cast alone! */
										UT_DEBUGMSG(("SDW: About to insert %u-%u\n", lastInsPos, i));
										size_t spanLen = i - lastInsPos;
										if (i == (len - 1)) spanLen++;
										UT_UCS4String span = textNode.substr(lastInsPos, spanLen);
										appendSpan(span.ucs4_str(), spanLen);
										lastInsPos = i;
									}
								}

								UT_VECTOR_PURGEALL(TextAttr*, charAttributes);
								break;

							}
							case SWG_JOBSETUP: {
								// flags are apparently unused here. no idea why they are there.
								gsf_off_t newpos;
								UT_uint8 flags;
								readFlagRec(mDocStream, flags, &newpos);
								if (gsf_input_seek(mDocStream, newpos, G_SEEK_SET))
									return UT_IE_BOGUSDOCUMENT;
								UT_uint16 len, system;
								streamRead(mDocStream, len);
								streamRead(mDocStream, system);
								char printerName[64];
								streamRead(mDocStream, printerName, 64);
								char deviceName[32], portName[32], driverName[32];
								streamRead(mDocStream, deviceName, 32);
								streamRead(mDocStream, portName, 32);
								streamRead(mDocStream, driverName, 32);
								UT_DEBUGMSG(("SDW: Jobsetup: len %u sys 0x%x printer |%.64s| device |%.32s| port |%.32s| driver |%.32s|\n", len, system, printerName, deviceName, portName, driverName));

								if (system == JOBSET_FILE364_SYSTEM || system == JOBSET_FILE605_SYSTEM) {
									UT_uint16 len2, system2;
									streamRead(mDocStream, len2);
									streamRead(mDocStream, system2);
									UT_uint32 ddl; // driver data length
									streamRead(mDocStream, ddl);
									// now the interesting data
									UT_uint16 orient; // 0=portrait 1=landscape
									streamRead(mDocStream, orient);
									UT_uint16 paperBin;
									streamRead(mDocStream, paperBin);
									UT_uint16 paperFormat;
									streamRead(mDocStream, paperFormat);
									UT_uint32 width, height;
									streamRead(mDocStream, width);
									streamRead(mDocStream, height);
									UT_DEBUGMSG(("SDW: orient %u bin %u format %u width %u height %u\n", orient, paperBin, paperFormat, width, height));
									// rest of the data is ignored, seems to be printer specific anyway.
									// Use A4, Portrait by default
									PP_PropertyVector attributes = {
										"pagetype", "a4", // A4/Letter/...
										"orientation", "portrait",
										"width", "210",
										"height", "297",
										"units", "mm"
									};
									const char* sdwPaperToAbi[] = {
										"A3",
										"A4",
										"A5",
										"B4",
										"B5",
										"Letter",
										"Legal",
										"Tabloid/Ledger",
										"Custom"
									};
									if (paperFormat < sizeof(sdwPaperToAbi)/sizeof(*sdwPaperToAbi)) {
										attributes[1] = sdwPaperToAbi[paperFormat];
                                    }
									const char* sdwOrientToAbi[] = {
										"portrait",
										"landscape"
									};
									if (orient < sizeof(sdwOrientToAbi)/sizeof(*sdwOrientToAbi)) {
										attributes[3] = sdwOrientToAbi[orient];
                                    }
									attributes[5] = UT_std_string_sprintf("%f", static_cast<double>(width)/100);
									attributes[7] = UT_std_string_sprintf("%f", static_cast<double>(height)/100);

									getDoc()->setPageSizeFromFile(attributes);
								}
								break;

							}
							case SWG_EOF:
								done2 = true;
								break;
							default:
								UT_DEBUGMSG(("SDW: SWG_CONTENT: Skipping %u bytes for record type '%c' (starting at 0x%08llX)\n",
											 size2, type,
											 (long long)gsf_input_tell(mDocStream)));
						}
						if (gsf_input_seek(mDocStream, eor2, G_SEEK_SET))
							return UT_IE_BOGUSDOCUMENT;
					}
					break;
				}
				case SWG_STRINGPOOL:
				{
					if (mDocHdr.nVersion <= SWG_POOLIDS) {
						UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED);
						break;
					}
					UT_uint8 encoding;
					streamRead(mDocStream, encoding);
					UT_iconv_t cd = findConverter(encoding);
					if (!UT_iconv_isValid(cd))
						throw UT_IE_IMPORTERROR;
					UT_uint16 count;
					streamRead(mDocStream, count);
					while (count--) {
						UT_uint16 id;
						streamRead(mDocStream, id);
						char* str;
						UT_uint16 len;
						::readByteString(mDocStream, str, &len);
						if (id == IDX_NOCONV_FF) {
							UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED);
						}
						// FIXME: find a way to not have to copy and free 
						// the result of UT_convert_cd.... --hub
						UT_DEBUGMSG(("SDW: StringPool: found 0x%04x <-> %.*s\n", id, len, str));
						UT_UCS4Char* convertedString = reinterpret_cast<UT_UCS4Char*>(UT_convert_cd(str, len + 1, cd, NULL, NULL));
						mStringPool.insert(stringpool_map::value_type(id, convertedString));
						FREEP(convertedString);
                        delete [] str;
					}
                    UT_iconv_close(cd);
					break;
				}
				case SWG_COMMENT: // skip over comments
					break;
				case SWG_EOF:
					done = true;
					break;
				default:
					UT_DEBUGMSG(("SDW: Skipping %u bytes for record type '%c' (starting at 0x%08llX)\n", recSize, type, (long long)gsf_input_tell(mDocStream)));
			}
			// Seek to the end of the record, in case it wasn't read completely
			if (gsf_input_seek(mDocStream, eor, G_SEEK_SET))
				return UT_IE_BOGUSDOCUMENT;
		}

		UT_DEBUGMSG(("SDW: Done\n"));

		return UT_OK;
	}
	catch(UT_Error e) {
		UT_DEBUGMSG(("SDW: error %d\n", e));
		return e;
	}
	catch(...) {
		UT_DEBUGMSG(("SDW: Unknown error\n"));
		return UT_IE_BOGUSDOCUMENT;
	}
}
示例#18
0
void IE_Imp_WordPerfect::closeEndnote()
{
	if (m_bHdrFtrOpenCount) return; // HACK
	X_CheckDocumentError(appendStrux(PTX_EndEndnote, PP_NOPROPS));
}
bool IE_Imp_MSWrite::read_pap (pap_t process)
{
	static const char *text_align[] = {"left", "center", "right", "justify"};
	int fcMac, pnPara, fcFirst, cfod, fc, fcLim;
	unsigned char page[0x80];
	UT_String properties, tmp, lastprops;

	if (process == All) { UT_DEBUGMSG(("PAP:\n")); }

	fcMac = wri_struct_value(wri_file_header, "fcMac");
	pnPara = wri_struct_value(wri_file_header, "pnPara");

	fcFirst = 0x80;

	while (true)
	{
		gsf_input_seek(mFile, pnPara++ * 0x80, G_SEEK_SET);
		gsf_input_read(mFile, 0x80, page);

		fc = READ_DWORD(page);
		cfod = page[0x7f];

		if (process == All)
		{
			UT_DEBUGMSG((" fcFirst = %d\n", fc));
			UT_DEBUGMSG((" cfod    = %d\n", cfod));
		}

		if (fc != fcFirst) UT_WARNINGMSG(("read_pap: fcFirst wrong.\n"));

		// read all FODs (format descriptors)
		for (int fod = 0; fod < cfod; fod++)
		{
			int bfprop, cch;
			int jc, dxaRight, dxaLeft, dxaLeft1, dyaLine, fGraphics;
			int rhcPage, rHeaderFooter, rhcFirst;
			int tabs, dxaTab[14], jcTab[14];

			if (process == All) { UT_DEBUGMSG(("  PAP-FOD #%02d:\n", fod + 1)); }

			// read a FOD (format descriptor)
			fcLim = READ_DWORD(page + 4 + fod * 6);
			bfprop = READ_WORD(page + 8 + fod * 6);

			if (process == All)
			{
				UT_DEBUGMSG(("   fcLim  = %d\n", fcLim));
				UT_DEBUGMSG((bfprop == 0xffff ? "   bfprop = 0x%04X\n" : "   bfprop = %d\n", bfprop));
			}

			// default PAP values
			jc = 0;
			dxaRight = dxaLeft = dxaLeft1 = 0;
			dyaLine = 240;
			rhcPage = rHeaderFooter = rhcFirst = 0;
			fGraphics = 0;
			tabs = 0;

			// if the PAP FPROPs (formatting properties) differ from the defaults, get them
			if (bfprop != 0xffff && bfprop + (cch = page[bfprop + 4]) < 0x80)
			{
				if (process == All) { UT_DEBUGMSG(("    cch = %d\n", cch)); }

				if (cch >= 2) jc = page[bfprop + 6] & 3;
				if (cch >= 6) dxaRight = READ_WORD(page + bfprop + 9);
				if (cch >= 8) dxaLeft = READ_WORD(page + bfprop + 11);
				if (cch >= 10) dxaLeft1 = READ_WORD(page + bfprop + 13);
				if (cch >= 12) dyaLine = READ_WORD(page + bfprop + 15);

				if (cch >= 17)
				{
					rhcPage = page[bfprop + 21] & 1;
					rHeaderFooter = page[bfprop + 21] & 6;
					rhcFirst = page[bfprop + 21] & 8;
					fGraphics = page[bfprop + 21] & 0x10;
				}

				for (int n = 0; n < 14; n++)
				{
					if (cch >= 4 * (n + 1) + 26)
					{
						dxaTab[tabs] = READ_WORD(page + bfprop + n * 4 + 27);
						jcTab[tabs] = page[bfprop + n * 4 + 29] & 3;
						tabs++;
					}
				}

				if (dxaRight & 0x8000) dxaRight = -0x10000 + dxaRight;
				if (dxaLeft & 0x8000) dxaLeft = -0x10000 + dxaLeft;
				if (dxaLeft1 & 0x8000) dxaLeft1 = -0x10000 + dxaLeft1;
				if (dyaLine < 240) dyaLine = 240;

				if (process == All && rHeaderFooter)
				{
					if (rhcPage)
					{
						if (!hasFooter)
						{
							hasFooter = true;
							page1Footer = rhcFirst;
						}
					}
					else
					{
						if (!hasHeader)
						{
							hasHeader = true;
							page1Header = rhcFirst;
						}
					}
				}
			}

			if ((process == All && !rHeaderFooter) ||
			    (rHeaderFooter && ((process == Header && !rhcPage) ||
			                       (process == Footer && rhcPage))))
			{
				UT_DEBUGMSG(("    jc            = %d\n", jc));
				UT_DEBUGMSG(("    dxaRight      = %d\n", dxaRight));
				UT_DEBUGMSG(("    dxaLeft       = %d\n", dxaLeft));
				UT_DEBUGMSG(("    dxaLeft1      = %d\n", dxaLeft1));
				UT_DEBUGMSG(("    dyaLine       = %d\n", dyaLine));
				UT_DEBUGMSG(("    rhcPage       = %d\n", rhcPage));
				UT_DEBUGMSG(("    rHeaderFooter = %d\n", rHeaderFooter));
				UT_DEBUGMSG(("    rhcFirst      = %d\n", rhcFirst));
				UT_DEBUGMSG(("    fGraphics     = %d\n", fGraphics));

				UT_LocaleTransactor lt(LC_NUMERIC, "C");
				UT_String_sprintf(properties, "text-align:%s; line-height:%.1f",
				                              text_align[jc],
				                              static_cast<float>(dyaLine) / 240.0);

				if (tabs)
				{
					properties += "; tabstops:";
					UT_DEBUGMSG(("    Tabs:\n"));

					for (int n = 0; n < tabs; n++)
					{
						UT_String_sprintf(tmp, "%.4fin/%c0",
						                       static_cast<float>(dxaTab[n]) / 1440.0,
						                       jcTab[n] ? 'D' : 'L');
						properties += tmp;
						UT_DEBUGMSG(("     #%02d dxa = %d, jcTab = %d\n", n + 1, dxaTab[n], jcTab[n]));

						if (n != tabs - 1) properties += ",";
					}
				}

				if (process == Header || process == Footer)
				{
					// For reasons unknown, the left and right margins from the paper
					// are included in the indents of the headers and footers.
					dxaLeft -= xaLeft;
					dxaRight -= xaRight;
				}

				if (dxaLeft1)
				{
					UT_String_sprintf(tmp, "; text-indent:%.4fin",
					                       static_cast<float>(dxaLeft1) / 1440.0);
					properties += tmp;
				}

				if (dxaLeft)
				{
					UT_String_sprintf(tmp, "; margin-left:%.4fin",
					                       static_cast<float>(dxaLeft) / 1440.0);
					properties += tmp;
				}

				if (dxaRight)
				{
					UT_String_sprintf(tmp, "; margin-right:%.4fin",
					                       static_cast<float>(dxaRight) / 1440.0);
					properties += tmp;
				}

				// new attributes, only if there was a line feed or FPROPs have changed
				if (lf || strcmp(properties.c_str(), lastprops.c_str()) != 0)
				{
					const gchar *attributes[3];

					attributes[0] = PT_PROPS_ATTRIBUTE_NAME;
					attributes[1] = properties.c_str();
					attributes[2] = NULL;

					appendStrux(PTX_Block, attributes);

					lastprops = properties;
				}

				if (fGraphics) read_pic(fcFirst, fcLim - fcFirst);
				else read_txt(fcFirst, fcLim - 1);
			}

			fcFirst = fcLim;

			if (fcLim >= fcMac)
			{
				UT_DEBUGMSG(("  PAP-FODs end, fcLim (%d) >= fcMac (%d)\n", fcLim, fcMac));
				return true;
			}
		}
	}
}
示例#20
0
/*!
 * Add the page attributes to the documents
 *
 * Set all page (section) attributes, and do an appendStrux(PTX_Section,...)
 * These settings are global for the whole document: Psion documents
 * contain only one single section.
 */
UT_Error IE_Imp_Psion::applyPageAttributes(const psiconv_page_layout_section layout,
                                           bool &with_header, bool &with_footer)
{
	UT_return_val_if_fail(layout != NULL, true /* perhaps should be false, but we want loading to proceed */);

	UT_UTF8String props,buffer;

	// Determine whether we have a header and a footer. We can't append them
	// here, because they have to come after the main section (or AbiWord will
	// become very confused).
	with_header = layout->header && layout->header->text && 
		          layout->header->text->paragraphs &&
		          psiconv_list_length(layout->header->text->paragraphs);
	with_footer = layout->footer && layout->footer->text && 
		          layout->footer->text->paragraphs &&
		          psiconv_list_length(layout->footer->text->paragraphs);

	const PP_PropertyVector propsArray = {
		// Page width
		"width", UT_std_string_sprintf("%6.3f", layout->page_width),
		// Page height
		"height", UT_std_string_sprintf("%6.3f", layout->page_width),
		// Units of width/height
		"units", "cm",
		// Orientation
		"orientation", layout->landscape ? "landscape" : "portrait",
		// Page type (we should check for common ones here!)
		"pagetype", "Custom"
	};

	if (!(getDoc()->setPageSizeFromFile(propsArray)))
		return UT_IE_IMPORTERROR;

	// First page number not yet implemented
	// On first page not yet implemented
	
	// left margin
	UT_UTF8String_sprintf(buffer,"page-margin-left:%6.3fcm",layout->left_margin);
	props += buffer;

	// right margin
	UT_UTF8String_sprintf(buffer,"; page-margin-right:%6.3fcm",layout->right_margin);
	props += buffer;

	// top margin
	UT_UTF8String_sprintf(buffer,"; page-margin-top:%6.3fcm",layout->top_margin);
	props += buffer;

	// bottom margin
	UT_UTF8String_sprintf(buffer,"; page-margin-bottom:%6.3fcm",layout->bottom_margin);
	props += buffer;
	
	// header distance
	UT_UTF8String_sprintf(buffer,"; page-margin-header:%6.3fcm",layout->header_dist);
	props += buffer;
	
	// footer distance
	UT_UTF8String_sprintf(buffer,"; page-margin-footer:%6.3fcm",layout->footer_dist);
	props += buffer;
	
	// Now actually append the properties in a PTX_Section strux to the document
	UT_DEBUGMSG(("PSION: Page: %s\n",props.utf8_str()));
	PP_PropertyVector propsArray2 = {
		"props", props.utf8_str()
	};
	if (with_header) {
		propsArray2.push_back("header");
		propsArray2.push_back("1");
	}
	if (with_footer) {
		propsArray2.push_back("footer");
		propsArray2.push_back("2");
	}
	if (!(appendStrux(PTX_Section,propsArray2))) {
		return UT_IE_IMPORTERROR;
	}
	return UT_OK;
}
示例#21
0
void IE_Imp_WordPerfect::openTableCell(const librevenge::RVNGPropertyList &propList)
{
	if (m_bHdrFtrOpenCount) return; // HACK
	int col =0,  row = 0, colSpan = 0, rowSpan = 0;
	if (propList["librevenge:column"])
		col = propList["librevenge:column"]->getInt();
	if (propList["librevenge:row"])
		row = propList["librevenge:row"]->getInt();
	if (propList["table:number-columns-spanned"])
		colSpan = propList["table:number-columns-spanned"]->getInt();
	if (propList["table:number-rows-spanned"])
		rowSpan = propList["table:number-rows-spanned"]->getInt();

	UT_DEBUGMSG(("AbiWordPerfect: openCell(col: %d, row: %d, colSpan: %d, rowSpan: %d\n", col, row, colSpan, rowSpan));
	if (m_bInCell)
	{
		X_CheckDocumentError(appendStrux(PTX_EndCell, PP_NOPROPS));
	}
	
	UT_String propBuffer;
	UT_String_sprintf(propBuffer, "left-attach:%d; right-attach:%d; top-attach:%d; bot-attach:%d",
					col, col+colSpan, row, row+rowSpan);
	
	UT_String borderStyle;
	// we only support bg-style:1 for now
	bool borderLeftSolid = false;
	bool borderRightSolid = false;
	bool borderTopSolid = false;
	bool borderBottomSolid = false;
	if (propList["fo:border-left"])
		borderLeftSolid = strncmp(propList["fo:border-left"]->getStr().cstr(), "0.0inch", 7);
	if (propList["fo:border-right"])
		borderRightSolid = strncmp(propList["fo:border-right"]->getStr().cstr(), "0.0inch", 7);
	if (propList["fo:border-top"])
		borderTopSolid = strncmp(propList["fo:border-top"]->getStr().cstr(), "0.0inch", 7);
	if (propList["fo:border-bottom"])
		borderBottomSolid = strncmp(propList["fo:border-bottom"]->getStr().cstr(), "0.0inch", 7);

	UT_String_sprintf(borderStyle, "; left-style:%s; right-style:%s; top-style:%s; bot-style:%s", 
					  (borderLeftSolid ? "solid" : "none"),
					  (borderRightSolid ? "solid" : "none"), 
					  (borderTopSolid ? "solid" : "none"), 
					  (borderBottomSolid ? "solid" : "none"));
	propBuffer += borderStyle;
		
	// we only support bg-style:1 for now
	if (propList["fo:background-color"])
	{
		UT_String bgCol;
		UT_String_sprintf(bgCol, "; bg-style:1; background-color:%s", &(propList["fo:background-color"]->getStr().cstr()[1]));
		propBuffer += bgCol;
	}
	
	UT_DEBUGMSG(("AbiWordPerfect: Inserting a Cell definition: %s\n", propBuffer.c_str()));
	
	const PP_PropertyVector propsArray = {
		"props", propBuffer.c_str()
	};

	X_CheckDocumentError(appendStrux(PTX_SectionCell, propsArray));
	m_bInCell = true;
}
示例#22
0
/*!  
 * Get all paragraph-related attributes and add them to the document.
 *
 * It does an appendStrux setting the current paragraph attributes and opening
 * a new paragraph. Several special cases are handled here too, mostly for
 * bullets.
 */
UT_Error IE_Imp_Psion::applyParagraphAttributes(const psiconv_paragraph_layout layout,
                      const gchar *stylename)
{
	UT_return_val_if_fail(layout != NULL, true /* perhaps should be false, but we want loading to proceed */);

	UT_UTF8String props;
	UT_Error res;

	// Get all attributes into prop
	if ((res = getParagraphAttributes(layout,props)))
		return UT_IE_IMPORTERROR;

	// HACK: Handle bullets
	// This is really, really ugly.
	// We can not really select the bullet symbol to use, so we do not even
	// try and just use always the plain round bullet.
	// Indent magic is done in getParagraphAttributes.
	if (layout->bullet->on) {
		props += ";list-style:Bullet List;field-font:Symbol";
		// We need to generate the list once, but only if we actually
		// have a bullet somewhere. Nasty. The attributes are mostly
		// black magickish...
		if (!list) {
			list = true;
			const PP_PropertyVector propsArray = {
				"id", global_listid,
				"parentid",	"0",
				"type",	"5",
				"start-value", "0",
				"list-delim", "%L",
				"list-decimal",	"NULL"
			};
			getDoc()->appendList(propsArray);
		}
	}

	// Prepare the properties for this paragraph strux
	UT_DEBUGMSG(("PSION: Paragraph: %s\n",props.utf8_str()));
	PP_PropertyVector propsArray = {
		"props", props.utf8_str(),
		"style", stylename
	};

	// Bullets need the listid too.
	if (layout->bullet->on) {
		propsArray.push_back("listid");
		propsArray.push_back(global_listid);
	}

	if (!(appendStrux(PTX_Block, propsArray))) {
		return UT_IE_IMPORTERROR;
	}

	// HACK: there is no real setting to do this. Yet.
	if (layout->on_next_page) {
		UT_UCSChar ucs = UCS_FF;
		if (!(appendSpan(&ucs,1)))
			return UT_IE_IMPORTERROR;
	}

	// We need to append a field and some other stuff...
	if (layout->bullet->on) {
		propsArray.resize(2);
		propsArray.push_back("type");
		propsArray.push_back("list_label");

		if (!(appendObject(PTO_Field,propsArray)))
			return UT_IE_IMPORTERROR;

		// In some cases, but not in all, we need a tab after the bullet.
		// See the Psiconv docs for the (ugly) details.
		if ((!layout->bullet->indent && (layout->indent_first > 0)) || 
			layout->bullet->indent) {
			UT_UCSChar uc = (UT_UCSChar) UCS_TAB;
			if (!(appendSpan(&uc,1)))
				return UT_IE_IMPORTERROR;
		}
	}
	return UT_OK;
}
bool IE_Imp_MSWrite::read_sep ()
{
	int pnSep, pnSetb;
	int yaMac, xaMac, yaTop, dyaText, dxaText, rStartPage, yaHeader, yaFooter;
	int cch, yaBot;
	unsigned char sep[0x80];

	UT_DEBUGMSG(("SEP:\n"));

	pnSep = wri_struct_value(wri_file_header, "pnSep");
	pnSetb = wri_struct_value(wri_file_header, "pnSetb");

	// default SEP values
	yaMac = 15840;
	xaMac = 12240;
	yaTop = 1440;
	dyaText = 12960;
	dxaText = 8640;
	xaLeft = 1800;
	rStartPage = 0xFFFF;
	yaHeader = 1080;
	yaFooter = 15760;

	// if the section properties differ from the defaults, get them
	if (pnSep != pnSetb)
	{
		gsf_input_seek(mFile, pnSep * 0x80, G_SEEK_SET);
		gsf_input_read(mFile, 0x80, sep);

		cch = *sep;
		UT_DEBUGMSG((" cch = %d\n", cch));

		if (cch >= 4) yaMac = READ_WORD(sep + 3);
		if (cch >= 6) xaMac = READ_WORD(sep + 5);
		if (cch >= 8) rStartPage = READ_WORD(sep + 7);
		if (cch >= 10) yaTop = READ_WORD(sep + 9);
		if (cch >= 12) dyaText = READ_WORD(sep + 11);
		if (cch >= 14) xaLeft = READ_WORD(sep + 13);
		if (cch >= 16) dxaText = READ_WORD(sep + 15);
		if (cch >= 20) yaHeader = READ_WORD(sep + 19);
		if (cch >= 22) yaFooter = READ_WORD(sep + 21);
	}

	if (rStartPage & 0x8000) rStartPage = -0x10000 + rStartPage;

	UT_DEBUGMSG((" yaMac      = %d\n", yaMac));
	UT_DEBUGMSG((" xaMac      = %d\n", xaMac));
	UT_DEBUGMSG((" rStartPage = %d\n", rStartPage));
	UT_DEBUGMSG((" yaTop      = %d\n", yaTop));
	UT_DEBUGMSG((" dyaText    = %d\n", dyaText));
	UT_DEBUGMSG((" xaLeft     = %d\n", xaLeft));
	UT_DEBUGMSG((" dxaText    = %d\n", dxaText));
	UT_DEBUGMSG((" yaHeader   = %d\n", yaHeader));
	UT_DEBUGMSG((" yaFooter   = %d\n", yaFooter));

	yaBot = yaMac - yaTop - dyaText;
	xaRight = xaMac - xaLeft - dxaText;

	UT_String properties;
	UT_LocaleTransactor lt(LC_NUMERIC, "C");
	UT_String_sprintf(properties, "page-margin-header:%.4fin; "
	                              "page-margin-right:%.4fin; "
	                              "page-margin-left:%.4fin; "
	                              "page-margin-top:%.4fin; "
	                              "page-margin-bottom:%.4fin; "
	                              "page-margin-footer:%.4fin",
	                              static_cast<float>(yaHeader) / 1440.0,
	                              static_cast<float>(xaRight) / 1440.0,
	                              static_cast<float>(xaLeft) / 1440.0,
	                              static_cast<float>(yaTop) / 1440.0,
	                              static_cast<float>(yaBot) / 1440.0,
	                              static_cast<float>(yaMac - yaFooter) / 1440.0);

	if (rStartPage >= 0)
	{
		UT_String tmp;
		UT_String_sprintf(tmp, "; section-restart:1"
		                       "; section-restart-value:%d", rStartPage);
		properties += tmp;
	}

	const gchar *attributes[11];

	attributes[0] = PT_PROPS_ATTRIBUTE_NAME;
	attributes[1] = properties.c_str();
	attributes[2] = PT_HEADERFIRST_ATTRIBUTE_NAME;
	attributes[3] = "0";
	attributes[4] = PT_HEADER_ATTRIBUTE_NAME;
	attributes[5] = "1";
	attributes[6] = PT_FOOTERFIRST_ATTRIBUTE_NAME;
	attributes[7] = "2";
	attributes[8] = PT_FOOTER_ATTRIBUTE_NAME;
	attributes[9] = "3";
	attributes[10] = NULL;

	appendStrux(PTX_Section, attributes);

	return true;
}