예제 #1
0
/**
 * Store the style in this automatic styles holder. As the specified
 * style get's stored here, this class takes care of freeing its memory later, so
 * you don't have to worry about freeing the memory of the stored style.
 * 
 * The style also get's it's unique name on this method.
 * 
 * After calling this method you may end up with your style pointer pointing to
 * a different style. It happens when there is already a stored style equivalent
 * to the one that you sent to be stored. The one that was passed is deleted.
 */
void ODe_AutomaticStyles::_storeStyle(ODe_Style_Style*& rpStyle,
                     UT_GenericStringMap<ODe_Style_Style*>& rStyles,
                     const char* pNamingPrefix) {
                        
    UT_GenericVector<ODe_Style_Style*>* pStyleVector;
    ODe_Style_Style* pStyle;
    bool isDuplicated;
    UT_uint32 i, count;
    
    pStyleVector = rStyles.enumerate();
    count = pStyleVector->getItemCount();
    
    for (i=0, isDuplicated=false; i<count && isDuplicated==false; i++) {
        
        pStyle = pStyleVector->getNthItem(i);
        if ( pStyle->isEquivalentTo(*rpStyle) ) {
            isDuplicated = true; // exit the loop
            delete rpStyle; // We don't want a duplicated style.
            rpStyle = pStyle;
        }
    }
    
    
    if (!isDuplicated) {
        // Let's name and store this style.
        UT_UTF8String styleName;
   
        UT_UTF8String_sprintf(styleName, "%s%d", pNamingPrefix, count+1);
        
        rpStyle->setStyleName(styleName);
        rStyles.insert(styleName.utf8_str(), rpStyle);
    }
}
예제 #2
0
ODe_Style_Style* ODe_AutomaticStyles::addTableCellStyle(
                                            const UT_UTF8String& rStyleName) {
    ODe_Style_Style* pStyle;
   
    pStyle = new ODe_Style_Style();
    pStyle->setStyleName(rStyleName);
    pStyle->setFamily("table-cell");
    
    m_tableCellStyles.insert(rStyleName.utf8_str(), pStyle);
    
    return pStyle;
}
void ODe_DocumentData::handleDefaultTabInterval(ODe_Style_Style* pStyle) {
    UT_return_if_fail(pStyle);
    
    UT_UTF8String defaultTabInterval = pStyle->getDefaultTabInterval();
    if (defaultTabInterval.empty())
        return;

    // remove the default tab interval property from the style
    pStyle->setDefaultTabInterval("");

    // ... and create a default style to hold the default tab interval property
    ODe_Style_Style* pDefaultStyle = m_styles.getDefaultStyles().getStyle("paragraph");
    if (!pDefaultStyle) {
        pDefaultStyle = new ODe_Style_Style();
        pDefaultStyle->setFamily("paragraph");
        pDefaultStyle->makeDefaultStyle();
        m_styles.getDefaultStyles().storeStyle("paragraph", pDefaultStyle);
    }
    // NOTE: if a paragraph default style already exists with a default tab interval
    // property set, then we'll just overwrite it. This can happen because AbiWord 
    // supports such a property on every paragraph and paragraph style, but ODT only 
    // supports one on the default paragraph style.
    pDefaultStyle->setDefaultTabInterval(defaultTabInterval);
}
예제 #4
0
void ODe_Frame_Listener::_openODTextbox(const PP_AttrProp& rAP,
                                        ODe_ListenerAction& /*rAction*/) 
{
    UT_UTF8String output;
    UT_UTF8String str;
    bool ok;
    const gchar* pValue = NULL;
    ODe_Style_Style* pStyle;
    
    pStyle = new ODe_Style_Style();
    pStyle->setFamily("graphic");
    pStyle->fetchAttributesFromAbiFrame(rAP);
    
    // Abi frames have no padding
    // (no margin between frame borders and its content)
    pStyle->setPadding("0cm");
    
    // Abi frames are aways positioned from its top-left corner.
    pStyle->setHorizontalPos("from-left");
    pStyle->setVerticalPos("from-top");
    
    // For OOo to recognize a textbox as being a textbox, it will
    // need to have the parent style name "Frame". I can't find it
    // in the ODF spec, but without it OOo considers the textbox to
    // be a generic drawing object (check the Navigator window in OOo).
    pStyle->setParentStyleName("Frame");
    // Make sure an (empty) Frame style exists, for completeness sake
	// (OOo doesn't seem to care if it exists or not).
    if (!m_rStyles.getGraphicsStyle("Frame")) {
        ODe_Style_Style* pFrameStyle = new ODe_Style_Style();
		pFrameStyle->setStyleName("Frame");
		pFrameStyle->setFamily("graphic");
        m_rStyles.addGraphicsStyle(pFrameStyle);
    }

	m_rAutomatiStyles.storeGraphicStyle(pStyle);

    ////
    // Write <draw:frame>
    
    _printSpacesOffset(output);
    output += "<draw:frame";

    UT_UTF8String_sprintf(str, "Frame%u", m_rAuxiliaryData.m_frameCount+1);
    ODe_writeAttribute(output, "draw:name", str);
    m_rAuxiliaryData.m_frameCount++;
    
    ODe_writeAttribute(output, "draw:style-name", pStyle->getName());

    UT_UTF8String_sprintf(str, "%u", m_zIndex);
    ODe_writeAttribute(output, "draw:z-index", str);


    ok = rAP.getProperty("position-to", pValue);

    if (pValue && !strcmp(pValue, "block-above-text")) {

        ODe_writeAttribute(output, "text:anchor-type", "paragraph");

        ok = rAP.getProperty("xpos", pValue);
        UT_ASSERT(ok && pValue != NULL);
        ODe_writeAttribute(output, "svg:x", pValue);

        ok = rAP.getProperty("ypos", pValue);
        UT_ASSERT(ok && pValue != NULL);
        ODe_writeAttribute(output, "svg:y", pValue);
    } else {
        // Everything else (column and page) will be treated as page
        // anchored.
        
        ODe_writeAttribute(output, "text:anchor-type", "page");

	if(pValue && !strcmp(pValue, "column-above-text"))
	{
	  //
	  // Get the most recent page style so we can do the arithmetic
	  // Won't work for x in multi-columned docs
	  //
	    UT_uint32 numPStyles =  m_rAutomatiStyles.getSectionStylesCount();
	    UT_UTF8String stylePName;
	    UT_UTF8String_sprintf(stylePName, "PLayout%d", numPStyles + 1);
	    ODe_Style_PageLayout * pPageL = m_rAutomatiStyles.getPageLayout(stylePName.utf8_str());

	    ok = rAP.getProperty("frame-col-xpos", pValue);
	    UT_ASSERT(ok && pValue != NULL);
	    double xCol =  UT_convertToInches(pValue);
	    const gchar* pSVal= pPageL->getPageMarginLeft();
	    double xPageL = UT_convertToInches(pSVal);
	    double xTot = xPageL + xCol;
	    pValue = UT_convertInchesToDimensionString(DIM_IN,xTot,"4");
	    ODe_writeAttribute(output, "svg:x", pValue);
        
	    ok = rAP.getProperty("frame-col-ypos", pValue);
	    UT_ASSERT(ok && pValue != NULL);
	    double yCol =  UT_convertToInches(pValue);
	    pSVal= pPageL->getPageMarginTop();
	    double yPageL = UT_convertToInches(pSVal);
	    double yTot = yPageL + yCol;
	    pValue = UT_convertInchesToDimensionString(DIM_IN,yTot,"4");
	    ODe_writeAttribute(output, "svg:y", pValue);	  
	}
	else
	{
	    ok = rAP.getProperty("frame-page-xpos", pValue);
	    UT_ASSERT(ok && pValue != NULL);
	    ODe_writeAttribute(output, "svg:x", pValue);
        
	    ok = rAP.getProperty("frame-page-ypos", pValue);
	    UT_ASSERT(ok && pValue != NULL);
	    ODe_writeAttribute(output, "svg:y", pValue);
	}
    }
    
    
    ok = rAP.getProperty("frame-width", pValue);
    if (ok && pValue != NULL) {
        ODe_writeAttribute(output, "svg:width", pValue);
    }
    
    output += ">\n";
    
    ODe_writeUTF8String(m_pTextOutput, output);
    m_spacesOffset++;
    
    ////
    // Write <draw:text-box>
    
    output.clear();
    _printSpacesOffset(output);
    output += "<draw:text-box";
    
    ok = rAP.getProperty("frame-height", pValue);
    if (ok && pValue != NULL) {
        ODe_writeAttribute(output, "fo:min-height", pValue);
    }
    
    output += ">\n";
    
    ODe_writeUTF8String(m_pTextOutput, output);
    m_spacesOffset++;
}