+static void render_para(para_data *pdata, paper_conf *conf,
+ keywordlist *keywords, indexdata *idx,
+ paragraph *index_placeholder, page_data *index_page)
+{
+ int last_x;
+ xref *cxref;
+ page_data *cxref_page;
+ xref_dest dest;
+ para_data *target;
+ line_data *ldata;
+
+ dest.type = NONE;
+ cxref = NULL;
+ cxref_page = NULL;
+
+ for (ldata = pdata->first; ldata; ldata = ldata->next) {
+ /*
+ * If this is a contents entry, we expect to have a single
+ * enormous cross-reference rectangle covering the whole
+ * thing. (Unless, of course, it spans multiple pages.)
+ */
+ if (pdata->contents_entry && ldata->page != cxref_page) {
+ cxref_page = ldata->page;
+ cxref = mknew(xref);
+ cxref->next = NULL;
+ cxref->dest.type = PAGE;
+ if (pdata->contents_entry == index_placeholder) {
+ cxref->dest.page = index_page;
+ } else {
+ assert(pdata->contents_entry->private_data);
+ target = (para_data *)pdata->contents_entry->private_data;
+ cxref->dest.page = target->first->page;
+ }
+ cxref->dest.url = NULL;
+ if (ldata->page->last_xref)
+ ldata->page->last_xref->next = cxref;
+ else
+ ldata->page->first_xref = cxref;
+ ldata->page->last_xref = cxref;
+ cxref->lx = conf->left_margin;
+ cxref->rx = conf->paper_width - conf->right_margin;
+ cxref->ty = conf->paper_height - conf->top_margin
+ - ldata->ypos + ldata->line_height;
+ }
+ if (pdata->contents_entry) {
+ assert(cxref != NULL);
+ cxref->by = conf->paper_height - conf->top_margin
+ - ldata->ypos;
+ }
+
+ last_x = render_line(ldata, conf->left_margin,
+ conf->paper_height - conf->top_margin,
+ &dest, keywords, idx);
+ if (ldata == pdata->last)
+ break;
+ }
+
+ /*
+ * If this is a contents entry, add leaders and a page
+ * number.
+ */
+ if (pdata->contents_entry) {
+ word *w;
+ wchar_t *num;
+ int wid;
+ int x;
+
+ if (pdata->contents_entry == index_placeholder) {
+ num = index_page->number;
+ } else {
+ assert(pdata->contents_entry->private_data);
+ target = (para_data *)pdata->contents_entry->private_data;
+ num = target->first->page->number;
+ }
+
+ w = fake_word(num);
+ wid = paper_width_simple(pdata, w);
+ sfree(w);
+
+ render_string(pdata->last->page,
+ pdata->fonts[FONT_NORMAL],
+ pdata->sizes[FONT_NORMAL],
+ conf->paper_width - conf->right_margin - wid,
+ (conf->paper_height - conf->top_margin -
+ pdata->last->ypos), num);
+
+ for (x = 0; x < conf->base_width; x += conf->leader_separation)
+ if (x - conf->leader_separation > last_x - conf->left_margin &&
+ x + conf->leader_separation < conf->base_width - wid)
+ render_string(pdata->last->page,
+ pdata->fonts[FONT_NORMAL],
+ pdata->sizes[FONT_NORMAL],
+ conf->left_margin + x,
+ (conf->paper_height - conf->top_margin -
+ pdata->last->ypos), L".");
+ }
+
+ /*
+ * Render any rectangle (chapter title underline or rule)
+ * that goes with this paragraph.
+ */
+ switch (pdata->rect_type) {
+ case RECT_CHAPTER_UNDERLINE:
+ add_rect_to_page(pdata->last->page,
+ conf->left_margin,
+ (conf->paper_height - conf->top_margin -
+ pdata->last->ypos -
+ conf->chapter_underline_depth),
+ conf->base_width,
+ conf->chapter_underline_thickness);
+ break;
+ case RECT_RULE:
+ add_rect_to_page(pdata->first->page,
+ conf->left_margin + pdata->first->xpos,
+ (conf->paper_height - conf->top_margin -
+ pdata->last->ypos -
+ pdata->last->line_height),
+ conf->base_width - pdata->first->xpos,
+ pdata->last->line_height);
+ break;
+ default: /* placate gcc */
+ break;
+ }
+}
+