Example #1
0
File: list.c Project: Bisheg/evince
void	listh_add_before(ListHead *head, List *at, List *list)
{
	if(at == head->head || head->head == NULL)
		listh_prepend(head, list);
	else {
		list->next = at;
		list->prev = at->prev;
		at->prev = list;
		head->count++;
	}
}
Example #2
0
/* used from context: params and device */
DviFontRef *
font_reference(
    DviParams *params,     /* rendering parameters */
    Int32 id,         /* external id number */
    const char *name,     /* font name */
    Int32 sum,         /* checksum (from DVI of VF) */
    int hdpi,         /* resolution */
    int vdpi,
    Int32 scale)        /* scaling factor (from DVI or VF) */
{
    DviFont    *font;
    DviFontRef *ref;
    DviFontRef *subfont_ref;
    
    /* see if there is a font with the same characteristics */
    for(font = (DviFont *)fontlist.head; font; font = font->next) {
        if(strcmp(name, font->fontname) == 0
           && (!sum || !font->checksum || font->checksum == sum)
           && font->hdpi == hdpi
           && font->vdpi == vdpi
           && font->scale == scale)
               break;
    }
    /* try to load the font */
    if(font == NULL) {
        font = mdvi_add_font(name, sum, hdpi, vdpi, scale);
        if(font == NULL)
            return NULL;
        listh_append(&fontlist, LIST(font));
    }
    if(!font->links && !font->chars && load_font_file(params, font) < 0) {
        DEBUG((DBG_FONTS, "font_reference(%s) -> Error\n", name));
        return NULL;
    }
    ref = xalloc(DviFontRef);
    ref->ref = font;

    font->links++;
    for(subfont_ref = font->subfonts; subfont_ref; subfont_ref = subfont_ref->next) {
        /* just adjust the reference counts */
        subfont_ref->ref->links++;
    }

    ref->fontid = id;

    if(LIST(font) != fontlist.head) {
        listh_remove(&fontlist, LIST(font));
        listh_prepend(&fontlist, LIST(font));
    }

    DEBUG((DBG_FONTS, "font_reference(%s) -> %d links\n",
        font->fontname, font->links));
    return ref;
}
Example #3
0
int	mdvi_register_special(const char *label, const char *prefix, 
	const char *regex, DviSpecialHandler handler, int replace)
{
	DviSpecial *sp;
	int	newsp = 0;

	if(!registered_builtins)
		register_builtin_specials();

	sp = find_special_prefix(prefix);
	if(sp == NULL) {
		sp = xalloc(DviSpecial);
		sp->prefix = mdvi_strdup(prefix);
		newsp = 1;
	} else if(!replace)
		return -1;
	else {
		mdvi_free(sp->label);
		sp->label = NULL;
	}

#ifdef WITH_REGEX_SPECIALS
	if(!newsp && sp->has_reg) {
		regfree(&sp->reg);
		sp->has_reg = 0;
	}
	if(regex && regcomp(&sp->reg, regex, REG_NOSUB) != 0) {
		if(newsp) {
			mdvi_free(sp->prefix);
			mdvi_free(sp);
		}
		return -1;
	}
	sp->has_reg = (regex != NULL);
#endif
	sp->handler = handler;
	sp->label = mdvi_strdup(label);
	sp->plen = strlen(prefix);
	if(newsp)
		listh_prepend(&specials, LIST(sp));		
	DEBUG((DBG_SPECIAL, 
		"New \\special handler `%s' with prefix `%s'\n", 
		label, prefix));
	return 0;
}