Exemplo n.º 1
0
static ImageInfo *getImageInfoObject(DFNode *concrete)
{
    DFNode *shape = DFChildWithTag(concrete,VML_SHAPE);
    DFNode *imageData = DFChildWithTag(shape,VML_IMAGEDATA);
    const char *cssText = DFGetAttribute(shape,NULL_STYLE);
    const char *rId = DFGetAttribute(imageData,OREL_ID);
    if ((shape == NULL) || (imageData == NULL) || (cssText == NULL) || (rId == NULL))
        return NULL;

    CSSProperties *imgProperties = CSSPropertiesNewWithString(cssText);
    CSSLength width = CSSLengthFromString(CSSGet(imgProperties,"width"));
    CSSLength height = CSSLengthFromString(CSSGet(imgProperties,"height"));
    CSSPropertiesRelease(imgProperties);

    if (!CSSLengthIsValid(width) || !CSSLengthIsAbsolute(width))
        return NULL;

    if (!CSSLengthIsValid(height) || !CSSLengthIsAbsolute(height))
        return NULL;

    double widthPts = convertBetweenUnits(width.value,width.units,UnitsPt);
    double heightPts = convertBetweenUnits(height.value,height.units,UnitsPt);

    ImageInfo *info = ImageInfoNew(rId,widthPts,heightPts);

    DFNode *oleObject = DFChildWithTag(concrete,MSOFFICE_OLEOBJECT);
    info->progId = DFGetAttribute(oleObject,NULL_PROGID);

    return info;
}
Exemplo n.º 2
0
static PointsSize pointsSizeFromHTMLImg(WordConverter *converter, DFNode *img, PixelSize fileSize)
{
    double aspectRatio;
    if (fileSize.heightPx > 0.0)
        aspectRatio = fileSize.widthPx/(double)fileSize.heightPx;
    else
        aspectRatio = 1.0;

    CSSSize htmlSize = HTML_getImageDimensions(img);

    double widthPts = WordSectionContentWidthPts(converter->mainSection);
    if (CSSLengthIsValid(htmlSize.width)) {
        if (CSSLengthIsPercentage(htmlSize.width))
            widthPts = (htmlSize.width.value/100.0)*WordSectionContentWidthPts(converter->mainSection);
        else if (CSSLengthIsAbsolute(htmlSize.width))
            widthPts = convertBetweenUnits(htmlSize.width.value,htmlSize.width.units,UnitsPt);
    }

    double heightPts = widthPts/aspectRatio;

    if ((widthPts <= 0) || (heightPts <= 0)) {
        widthPts = WordSectionContentWidthPts(converter->mainSection);
        heightPts = widthPts/aspectRatio;
    }

    PointsSize result;
    result.widthPts = widthPts;
    result.heightPts = heightPts;
    return result;
}
Exemplo n.º 3
0
double CSSLengthToAbsolute(CSSLength length, double total, double valueUnits)
{
    switch (length.units) {
        case UnitsIn:
        case UnitsCm:
        case UnitsMm:
        case UnitsPt:
        case UnitsPc:
        case UnitsPx:
            return convertBetweenUnits(length.value,length.units,valueUnits);
        case UnitsPct:
            return (length.value/100.0)*total;
        default:
            return 0;
    }
}