Example #1
0
static void do_links(fz_link *link, int xofs, int yofs)
{
    fz_rect r;
    float x, y;

    x = ui.x;
    y = ui.y;

    xofs -= page_tex.x;
    yofs -= page_tex.y;

    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    while (link)
    {
        r = link->rect;
        fz_transform_rect(&r, &page_ctm);

        if (x >= xofs + r.x0 && x < xofs + r.x1 && y >= yofs + r.y0 && y < yofs + r.y1)
        {
            ui.hot = link;
            if (!ui.active && ui.down)
                ui.active = link;
        }

        if (ui.hot == link || showlinks)
        {
            if (ui.active == link && ui.hot == link)
                glColor4f(0, 0, 1, 0.4f);
            else if (ui.hot == link)
                glColor4f(0, 0, 1, 0.2f);
            else
                glColor4f(0, 0, 1, 0.1f);
            glRectf(xofs + r.x0, yofs + r.y0, xofs + r.x1, yofs + r.y1);
        }

        if (ui.active == link && !ui.down)
        {
            if (ui.hot == link)
            {
                if (fz_is_external_link(ctx, link->uri))
                    open_browser(link->uri);
                else
                {
                    jump_to_page(fz_resolve_link(ctx, doc, link->uri, NULL, NULL));
                    ui_needs_update = 1;
                }
            }
        }

        link = link->next;
    }

    glDisable(GL_BLEND);
}
Example #2
0
static void
build_index(fz_context* ctx, fz_document* document, fz_outline* outline, girara_tree_node_t* root)
{
  if (outline == NULL || root == NULL) {
    return;
  }

  while (outline != NULL) {
    zathura_index_element_t* index_element = zathura_index_element_new(outline->title);
    zathura_link_target_t target           = { ZATHURA_LINK_DESTINATION_UNKNOWN, NULL, 0, -1, -1, -1, -1, 0 };
    zathura_link_type_t type               = ZATHURA_LINK_INVALID;
    zathura_rectangle_t rect               = { .x1 = 0, .y1 = 0, .x2 = 0, .y2 = 0 };

    if (outline->uri == NULL) {
      type = ZATHURA_LINK_NONE;
    } else if (fz_is_external_link(ctx, outline->uri) == 1) {
      if (strstr(outline->uri, "file://") == outline->uri) {
        type         = ZATHURA_LINK_GOTO_REMOTE;
        target.value = outline->uri;
      } else {
        type         = ZATHURA_LINK_URI;
        target.value = outline->uri;
      }
    } else {
      float x = 0;
      float y = 0;

      type                    = ZATHURA_LINK_GOTO_DEST;
      target.destination_type = ZATHURA_LINK_DESTINATION_XYZ;
      target.page_number      = fz_resolve_link(ctx, document, outline->uri, &x, &y);
      target.left  = x;
      target.top   = y;
      target.zoom  = 0.0;
    }

    index_element->link = zathura_link_new(type, rect, target);
    if (index_element->link == NULL) {
      outline = outline->next;
      continue;
    }

    girara_tree_node_t* node = girara_node_append_data(root, index_element);

    if (outline->down != NULL) {
      build_index(ctx, document, outline->down, node);
    }

    outline = outline->next;
  }
}