Example #1
0
int main(int argc, char** argv)
{
    css::CSSStyleSheet defaultStyleSheet(0);
    Document document(0);

    // Load the default CSS file
    if (1 < argc) {
        std::ifstream stream(argv[1]);
        if (!stream) {
            std::cerr << "error: cannot open " << argv[1] << ".\n";
            return EXIT_FAILURE;
        }
        defaultStyleSheet = loadStyleSheet(stream);
        getDOMImplementation()->setDefaultStyleSheet(defaultStyleSheet);
    }

    document = loadDocument(htmlDocument);
    assert(document);

    // Each HTML element will have a style attribute if there's the style content attribute.
    // Each HTML style element will have a style sheet.
    eval(document);

    dumpTree(std::cout, document);

    // create the default view
    DocumentWindowPtr window = new(std::nothrow) DocumentWindow;
    window->setDocument(document);
    ViewCSSImp* view = new ViewCSSImp(window);
    view->setSize(8.5f * 96, 11.0f * 96);  // US letter size, 96 DPI
    view->constructComputedStyles();
    view->calculateComputedStyles();

    Box* boxTree = view->constructBlocks();
    if (!boxTree)
        return EXIT_FAILURE;

    boxTree->dump();

    std::cout << "done.\n";
    return 0;
}