示例#1
0
TreeNode *Parser::object_sequence()
{
    float number = m_token->to_number();
    match(NUM);
    float generation_nunber = m_token->to_number();
    match(NUM);

    ObjNode *node = new ObjNode((int) number, (int) generation_nunber);
    match(OBJ);
    node->set_value(value_sequence());
    if (m_token && m_token->type() == STREAM) {
        int length = 0;
        MapNode *map = dynamic_cast<MapNode *> (node->value());
        if (map) {
            NumberNode *number = dynamic_cast<NumberNode *> (map->get("/Length"));
            if (number) {
                length = number->value();
            }
        }
        node->set_stream_pos(m_scanner->ignore_stream(length));
        next_token();
        match(END_STREAM);
    }
    match(END_OBJ);

    return node;
}
示例#2
0
void Parser::object_streams(RootNode *root_node)
{
    int size = root_node->size();
    int i;

    for (i = 0; i < size; i++) {
        ObjNode *root_object = dynamic_cast<ObjNode *> (root_node->get(i));
        if (root_object) {
            MapNode *map = dynamic_cast<MapNode *> (root_object->value());
            if (map) {
                NameNode *type = dynamic_cast<NameNode *> (map->get("/Type"));
                if (type && type->name() == "/ObjStm") {
                    int qtd = 0;
                    int length = 0;
                    NumberNode *number = dynamic_cast<NumberNode *> (map->get("/N"));
                    if (number) {
                        qtd = number->value();
                    }
                    NumberNode *length_node = dynamic_cast<NumberNode *> (map->get("/Length"));
                    if (number) {
                        length = length_node->value();
                    }
                    char *uncompressed = NULL;

                    m_scanner->to_pos(root_object->stream_pos());
                    char *stream = (char *)m_scanner->get_stream(length);

                    int total = length;
                    NameNode *filter = dynamic_cast<NameNode *> (map->get("/Filter"));
                    if (filter && filter->name() == "/FlateDecode") {
                        uncompressed = flat_decode(stream, length, total);
                        delete [] stream;
                    } else if (!filter) {
                        uncompressed = stream;
                    } else {
                        error_message(string("compression not supported: ") + filter->name());
                        return;
                    }
                    stringstream stream_value;
                    stream_value.write(uncompressed, total);
                    stream_value.seekg(0);
                    delete [] uncompressed;

                    Scanner scanner;
                    Scanner *temp = m_scanner;
                    m_scanner = &scanner;
                    scanner.set_istream(&stream_value);

                    vector<int> ids;
                    int loop;
                    for (loop = 0; loop < qtd; loop++) {
                        next_token();
                        ids.push_back(m_token->to_number());
                        next_token();
                    }
                    next_token();
                    vector<int>::iterator id;
                    for (id = ids.begin(); id < ids.end(); id++) {
                        ObjNode *new_obj = new ObjNode(*id, 0);
                        new_obj->set_value(value_sequence());
                        root_node->add_child(new_obj);
                    }
                    m_scanner = temp;
                }
            }
        }
    }
}