fz_rect getContainingRect( fz_node *node, fz_rect maxRect ) { fz_rect rect = fz_emptyrect; if (node) { switch(node->kind) { case FZ_NTEXT: case FZ_NIMAGE: case FZ_NPATH: if (isInsideRect(maxRect, node->bbox)) rect = fz_mergerects(rect, node->bbox); break; default: break; } // Recurse for (fz_node *child = node->first; child; child = child->next) rect = fz_mergerects(rect, getContainingRect(child, maxRect)); } return rect; }
/* * Over */ fz_error fz_newovernode(fz_node **nodep) { fz_node *node; node = *nodep = fz_malloc(sizeof (fz_overnode)); if (!node) return fz_rethrow(-1, "out of memory"); fz_initnode(node, FZ_NOVER); return fz_okay; } #if 0 /* cf. http://code.google.com/p/sumatrapdf/issues/detail?id=533 */ fz_rect fz_boundovernode(fz_overnode *node, fz_matrix ctm) { fz_node *child; fz_rect bbox; fz_rect temp; child = node->super.first; if (!child) return fz_emptyrect; bbox = fz_boundnode(child, ctm); child = child->next; while (child) { temp = fz_boundnode(child, ctm); bbox = fz_mergerects(temp, bbox); child = child->next; } return bbox; }
fz_rect fz_boundovernode(fz_overnode *node, fz_matrix ctm) { struct { int cap, ix; struct { fz_node *node; fz_rect bbox; } *items; } stack; fz_node *child = node->super.first; fz_rect bbox = fz_emptyrect; fz_rect temp; if (!child) return fz_emptyrect; stack.cap = 8; stack.ix = 0; stack.items = nil; do { if (child->kind != FZ_NOVER) { temp = fz_boundnode(child, ctm); bbox = fz_mergerects(temp, bbox); child = child->next; } else if (child->first) { if (!stack.items) stack.items = fz_malloc(stack.cap * sizeof(*stack.items)); else if (stack.ix >= stack.cap) { stack.cap *= 2; stack.items = fz_realloc(stack.items, stack.cap * sizeof(*stack.items)); if (!stack.items) return fz_emptyrect; } stack.items[stack.ix].node = child; stack.items[stack.ix].bbox = bbox; stack.ix++; bbox = fz_emptyrect; child = child->first; } else { child = child->next; } while (!child && stack.ix > 0) { stack.ix--; temp = stack.items[stack.ix].bbox; bbox = fz_mergerects(temp, bbox); child = stack.items[stack.ix].node->next; } } while (child); fz_free(stack.items); return bbox; }