⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fserve.c

📁 远程桌面连接工具
💻 C
📖 第 1 页 / 共 5 页
字号:
	/* make the font */	newfont = (FontPtr) xalloc(sizeof(FontRec));	/* and the FS data */	fsd = (FSFontDataPtr) xalloc(sizeof(FSFontDataRec));	fsfont = (FSFontPtr) xalloc(sizeof(FSFontRec));	fontname = (char *)xalloc(namelen);	if (!newfont || !fsd || !fsfont || !fontname) {lowmem:	    if (!(flags & FontReopen))	    {		xfree((char *) newfont);		xfree((char *) fsd);		xfree((char *) fsfont);		xfree((char *) fontname);	    }	    if (blockrec) fs_abort_blockrec(conn, blockrec);	    return AllocError;	}	bzero((char *) newfont, sizeof(FontRec));	bzero((char *) fsfont, sizeof(FSFontRec));	bzero((char *) fsd, sizeof(FSFontDataRec));    }    /* make a new block record, and add it to the end of the list */    blockrec = fs_new_block_rec(fpe, client, FS_OPEN_FONT);    if (!blockrec) {	goto lowmem;    }    if (!(flags & FontReopen))    {	int bit, byte, scan, glyph;	newfont->refcnt = 0;	newfont->maxPrivate = -1;	newfont->devPrivates = (pointer *) 0;	newfont->format = format;	/* These font components will be needed in packGlyphs */	CheckFSFormat(format, BitmapFormatMaskBit |			      BitmapFormatMaskByte |			      BitmapFormatMaskScanLineUnit |			      BitmapFormatMaskScanLinePad,		      &bit,		      &byte,		      &scan,		      &glyph,		      NULL);	newfont->bit = bit;	newfont->byte = byte;	newfont->scan = scan;	newfont->glyph = glyph;	newfont->fpe = fpe;	newfont->fpePrivate = (pointer) fsd;	newfont->fontPrivate = (pointer) fsfont;	_fs_init_font(newfont);	fsd->fpe = fpe;	fsd->name = fontname;	fsd->namelen = namelen;	memcpy(fontname, name, namelen);	fsd->format = format;	fsd->fmask = fmask;    }    fsd->fontid = newid;    fsd->generation = conn->generation;    blockedfont = (FSBlockedFontPtr) blockrec->data;    blockedfont->fontid = newid;    blockedfont->pfont = newfont;    blockedfont->state = FS_OPEN_REPLY;    blockedfont->flags = flags;    blockedfont->format = format;    blockedfont->clients_depending = (FSClientsDependingPtr)0;    /* save the ID */    if (!StoreFontClientFont(blockedfont->pfont, blockedfont->fontid)) {	goto lowmem;    }    /* do an FS_OpenFont, FS_QueryXInfo and FS_QueryXExtents */    buf[0] = (unsigned char) namelen;    memcpy(&buf[1], name, namelen);    namelen++;    openreq.reqType = FS_OpenBitmapFont;    openreq.fid = newid;    openreq.format_hint = format;    openreq.format_mask = fmask;    openreq.length = (SIZEOF(fsOpenBitmapFontReq) + namelen + 3) >> 2;    _fs_add_req_log(conn, FS_OpenBitmapFont);    _fs_write(conn, (char *) &openreq, SIZEOF(fsOpenBitmapFontReq));    _fs_write_pad(conn, (char *) buf, namelen);#ifdef NCD    if (configData.ExtendedFontDiags) {	memcpy(buf, name, MIN(256, namelen));	buf[MIN(256, namelen)] = '\0';	printf("Requesting font \"%s\" from font server \"%s\"\n",	       buf, fpe->name);    }#endif    if (flags & FontOpenSync) {	err = fs_do_open_font(fpe, blockrec, TRUE);	if (blockedfont->errcode == Successful) {	    *ppfont = blockedfont->pfont;	} else {	    _fs_cleanup_font(blockedfont);	}	_fs_remove_block_rec(conn, blockrec);    }    return err;}static intfs_send_query_info(fpe, blockrec)    FontPathElementPtr fpe;    FSBlockDataPtr blockrec;{    FSBlockedFontPtr bfont;    FSFpePtr    conn = (FSFpePtr) fpe->private;    fsQueryXInfoReq inforeq;    bfont = (FSBlockedFontPtr) blockrec->data;    inforeq.reqType = FS_QueryXInfo;    inforeq.id = bfont->fontid;    inforeq.length = SIZEOF(fsQueryXInfoReq) >> 2;    blockrec->sequence_number = conn->current_seq;    _fs_add_req_log(conn, FS_QueryXInfo);    _fs_write(conn, (char *) &inforeq, SIZEOF(fsQueryXInfoReq));    return Successful;}static intfs_send_query_extents(fpe, blockrec)    FontPathElementPtr fpe;    FSBlockDataPtr blockrec;{    FSBlockedFontPtr bfont;    FSFpePtr    conn = (FSFpePtr) fpe->private;    fsQueryXExtents16Req extreq;    bfont = (FSBlockedFontPtr) blockrec->data;    extreq.reqType = FS_QueryXExtents16;    extreq.range = fsTrue;    extreq.fid = bfont->fontid;    extreq.num_ranges = 0;    extreq.length = SIZEOF(fsQueryXExtents16Req) >> 2;    blockrec->sequence_number = conn->current_seq;    _fs_add_req_log(conn, FS_QueryXExtents16);    _fs_write(conn, (char *) &extreq, SIZEOF(fsQueryXExtents16Req));    return Successful;}static intfs_send_query_bitmaps(fpe, blockrec)    FontPathElementPtr fpe;    FSBlockDataPtr blockrec;{    FSBlockedFontPtr bfont;    FSFpePtr    conn = (FSFpePtr) fpe->private;    fsQueryXBitmaps16Req bitreq;    bfont = (FSBlockedFontPtr) blockrec->data;    /* send the request */    bitreq.reqType = FS_QueryXBitmaps16;    bitreq.fid = bfont->fontid;    bitreq.format = bfont->format;    bitreq.range = TRUE;    bitreq.length = SIZEOF(fsQueryXBitmaps16Req) >> 2;    bitreq.num_ranges = 0;    blockrec->sequence_number = conn->current_seq;    _fs_add_req_log(conn, FS_QueryXBitmaps16);    _fs_write(conn, (char *) &bitreq, SIZEOF(fsQueryXBitmaps16Req));    return Successful;}/* ARGSUSED */static intfs_open_font(client, fpe, flags, name, namelen, format, fmask, id, ppfont,	     alias, non_cachable_font)    pointer     client;    FontPathElementPtr fpe;    Mask        flags;    char       *name;    fsBitmapFormat format;    fsBitmapFormatMask fmask;    int         namelen;    XID         id;    FontPtr    *ppfont;    char      **alias;    FontPtr     non_cachable_font;	/* Not used in this FPE */{    FSFpePtr    conn = (FSFpePtr) fpe->private;    FSBlockDataPtr blockrec;    FSBlockedFontPtr blockedfont;    int         err;    /* libfont interface expects ImageRectMin glyphs */    format = format & ~BitmapFormatImageRectMask | BitmapFormatImageRectMin;    *alias = (char *) 0;    /* XX if we find the blockrec for the font */    blockrec = (FSBlockDataPtr) conn->blocked_requests;    while (blockrec != (FSBlockDataPtr) 0) {	if (blockrec->type == FS_OPEN_FONT &&		blockrec->client == client) {	    blockedfont = (FSBlockedFontPtr) blockrec->data;	    err = blockedfont->errcode;	    if (err == Successful) {		*ppfont = blockedfont->pfont;	    } else {		_fs_cleanup_font(blockedfont);	    }	    /* cleanup */	    _fs_remove_block_rec(conn, blockrec);	    return err;	}	blockrec = blockrec->next;    }    return fs_send_open_font(client, fpe, flags, name, namelen, format, fmask,			     id, ppfont);}/* ARGSUSED */static intfs_send_close_font(fpe, id)    FontPathElementPtr fpe;    Font        id;{    FSFpePtr    conn = (FSFpePtr) fpe->private;    fsCloseReq  req;    /* tell the font server to close the font */    req.reqType = FS_CloseFont;    req.length = SIZEOF(fsCloseReq) >> 2;    req.id = id;    _fs_add_req_log(conn, FS_CloseFont);    _fs_write(conn, (char *) &req, SIZEOF(fsCloseReq));    return Successful;}/* ARGSUSED */static intfs_close_font(fpe, pfont)    FontPathElementPtr fpe;    FontPtr     pfont;{    FSFontDataPtr fsd = (FSFontDataPtr) pfont->fpePrivate;    FSFpePtr    conn = (FSFpePtr) fpe->private;    /* XXX we may get called after the resource DB has been cleaned out */    if (find_old_font(fsd->fontid))	DeleteFontClientID(fsd->fontid);    if (conn->generation == fsd->generation)	fs_send_close_font(fpe, fsd->fontid);    (*pfont->unload_font) (pfont);    xfree(fsd->name);    xfree(fsd);    xfree(pfont->info.isStringProp);    xfree(pfont->info.props);    xfree(pfont->devPrivates);    xfree(pfont);    return Successful;}static intfs_read_glyphs(fpe, blockrec)    FontPathElementPtr fpe;    FSBlockDataPtr blockrec;{    FSBlockedGlyphPtr bglyph = (FSBlockedGlyphPtr) blockrec->data;    FSBlockedFontPtr bfont = (FSBlockedFontPtr) blockrec->data;    FSFpePtr    conn = (FSFpePtr) fpe->private;    FontPtr pfont = bglyph->pfont;      /* works for either blocked font					   or glyph rec...  pfont is at					   the very beginning of both					   blockrec->data structures */    FSFontDataPtr fsd = (FSFontDataPtr) (pfont->fpePrivate);    FSFontPtr   fsdata = (FSFontPtr) pfont->fontPrivate;    FontInfoPtr	pfi = &pfont->info;    fsQueryXBitmaps16Reply rep;    fsOffset32   *ppbits;    fsOffset32	local_off;    char	*off_adr;    pointer     pbitmaps;    char	*bits;    int         glyph_size,                offset_size,                i,		err;    int		nranges = 0;    fsRange	*ranges, *nextrange;    unsigned long minchar, maxchar;    /* get reply header */    memcpy(&rep, &blockrec->header, SIZEOF(fsGenericReply));    if (rep.type == FS_Error) {/* XXX -- translate FS error */	_fs_eat_rest_of_error(conn, (fsError *) & rep);	err = AllocError;	goto bail;    }    if (_fs_read(conn, (char *) &rep + SIZEOF(fsGenericReply),	      SIZEOF(fsQueryXBitmaps16Reply) - SIZEOF(fsGenericReply)) == -1) {	if (blockrec->type == FS_OPEN_FONT)	    fs_free_font(bfont);	return StillWorking;    }    /* allocate space for glyphs */    offset_size = SIZEOF(fsOffset32) * (rep.num_chars);    glyph_size = (rep.length << 2) - SIZEOF(fsQueryXBitmaps16Reply)	- offset_size;    ppbits = (fsOffset32 *) xalloc(offset_size);    pbitmaps = (pointer) xalloc(glyph_size);    if (glyph_size && !pbitmaps || !ppbits)    {	xfree(pbitmaps);	xfree(ppbits);	/* clear wire */	(void) _fs_drain_bytes_pad(conn, offset_size);	(void) _fs_drain_bytes_pad(conn, glyph_size);	if (blockrec->type == FS_OPEN_FONT)	    _fs_cleanup_font(bfont);	err = AllocError;	goto bail;    }    /* read offsets */    if (_fs_read_pad(conn, (char *) ppbits, offset_size) == -1) {	if (blockrec->type == FS_OPEN_FONT)	    fs_free_font(bfont);	return StillWorking;    }    /* read glyphs */    if (_fs_read_pad(conn, (char *) pbitmaps, glyph_size) == -1) {	if (blockrec->type == FS_OPEN_FONT)	    fs_free_font(bfont);	return StillWorking;    }    if (blockrec->type == FS_LOAD_GLYPHS)    {	nranges = bglyph->num_expected_ranges;	nextrange = ranges = bglyph->expected_ranges;    }    /* place the incoming glyphs */    if (nranges)    {	/* We're operating under the assumption that the ranges	   requested in the LoadGlyphs call were all legal for this	   font, and that individual ranges do not cover multiple	   rows...  fs_build_range() is designed to ensure this. */	minchar = (nextrange->min_char_high - pfi->firstRow) *		  (pfi->lastCol - pfi->firstCol + 1) +		  nextrange->min_char_low - pfi->firstCol;	maxchar = (nextrange->max_char_high - pfi->firstRow) *		  (pfi->lastCol - pfi->firstCol + 1) +		  nextrange->max_char_low - pfi->firstCol;	nextrange++;    }    else    {	minchar = 0;	maxchar = rep.num_chars;    }    off_adr = (char *)ppbits;    for (i = 0; i < rep.num_chars; i++)    {	memcpy(&local_off, off_adr, SIZEOF(fsOffset32));	/* align it */	if (blockrec->type == FS_OPEN_FONT ||	    fsdata->encoding[minchar].bits == &_fs_glyph_requested)	{	    if (local_off.length)	    {		bits = (char *)xalloc(local_off.length);		if (bits == NULL)		{		    xfree(ppbits);		    xfree(pbitmaps);		    err = AllocError;		    goto bail;		}		memcpy(bits, pbitmaps + local_off.position,		       local_off.length);	    }	    else if (NONZEROMETRICS(&fsdata->encoding[minchar].metrics))		bits = &_fs_glyph_zero_length;	    else		bits = 0;	    if (fsdata->encoding[minchar].bits == &_fs_glyph_requested)		fsd->glyphs_to_get--;	    fsdata->encoding[minchar].bits = bits;	}	if (minchar++ == maxchar)	{	    if (!--nranges) break;	    minchar = (nextrange->min_char_high - pfi->firstRow) *		      (pfi->lastCol - pfi->firstCol + 1) +		      nextrange->min_char_low - pfi->firstCol;	    maxchar = (nextrange->max_char_high - pfi->firstRow) *		      (pfi->lastCol - pfi->firstCol + 1) +		      nextrange->max_char_low - pfi->firstCol;	    nextrange++;	}	off_adr += SIZEOF(fsOffset32);    }    xfree(ppbits);    xfree(pbitmaps);    if (blockrec->type == FS_OPEN_FONT)    {	fsd->glyphs_to_get = 0;	bfont->state = FS_DONE_REPLY;    }    err = Successful;bail:    if (blockrec->type == FS_LOAD_GLYPHS)    {	bglyph->done = TRUE;	bglyph->errcode = err;    }    return err;}static intfs_send_load_glyphs(client, pfont, nranges, ranges)    pointer     client;    FontPtr     pfont;    int		nranges;    fsRange	*ranges;{    FSBlockedGlyphPtr blockedglyph;    fsQueryXBitmaps16Req req;    FSFontDataPtr fsd = (FSFontDataPtr) (pfont->fpePrivate);    FontPathElementPtr fpe = fsd->fpe;    FSFpePtr    conn = (FSFpePtr) fpe->private;    FSBlockDataPtr blockrec;    /* make a new block record, and add it to the end of the list */    blockrec = fs_new_block_rec(fpe, client, FS_LOAD_GLYPHS);    if (!blockrec)	return AllocError;    blockedglyph = (FSBlockedGlyphPtr) blockrec->data;    blockedglyph->pfont = pfont;    blockedglyph->num_expected_ranges = nranges;    /* Assumption: it's our job to free ranges */    blockedglyph->expected_ranges = ranges;    blockedglyph->done = FALSE;    blockedglyph->clients_depending = (FSClientsDependingPtr)0;    blockrec->sequence_number = conn->current_seq;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -