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

📄 bitscale.c

📁 远程桌面连接工具
💻 C
📖 第 1 页 / 共 4 页
字号:
		    best_unscaled_rescale_x = rescale_x;		}	    }	}    }    if (best_unscaled)    {	*best = best_unscaled->vals;	*fpep = best_unscaled_fpe;	*dxp = 1.0;	*dyp = 1.0;	*sdxp = best_unscaled_sdx;	*sdyp = best_unscaled_sdy;	rescale_x = best_unscaled_rescale_x;	result = best_unscaled->bitmap;    }    else if (best_scaled)    {	*best = best_scaled->vals;	*fpep = best_fpe;	*dxp = best_dx;	*dyp = best_dy;	*sdxp = best_sdx;	*sdyp = best_sdy;	rescale_x = best_rescale_x;	result = best_scaled->bitmap;    }    else	result = NULL;    if (bitmap != NULL && (result == NULL || *dxp != 1.0 || *dyp != 1.0))    {	*fpep = bitmap_fpe;	FontParseXLFDName (bitmap->name.name, best, FONT_XLFD_REPLACE_NONE);	if (ComputeScaleFactors(best, best, dxp, dyp, sdxp, sdyp, &rescale_x))	    result = bitmap;	else	    result = NULL;    }    if (result && rescale_x != 1.0)    {	/* We have rescaled horizontally due to an XLFD width field.  Change	   the matrix appropriately */	vals->pixel_matrix[0] *= rescale_x;	vals->pixel_matrix[1] *= rescale_x;#ifdef NOTDEF	/* This would force the pointsize and pixelsize fields in the	   FONT property to display as matrices to more accurately	   report the font being supplied.  It might also break existing	   applications that expect a single number in that field. */	vals->values_supplied =	    vals->values_supplied & ~(PIXELSIZE_MASK | POINTSIZE_MASK) |	    PIXELSIZE_ARRAY;#else /* NOTDEF */	vals->values_supplied = vals->values_supplied & ~POINTSIZE_MASK;#endif /* NOTDEF */	/* Recompute and reround the FontScalablePtr values after	   rescaling for the new width. */	FontFileCompleteXLFD(vals, vals);    }    return result;}static FontEntryPtrFindPmfToScale(fpe, entry, vals, best, dxp, dyp, sdxp, sdyp, fpep)    FontPathElementPtr	fpe;    FontEntryPtr	entry;    FontScalablePtr	vals,			best;    double		*dxp, *sdxp,			*dyp, *sdyp;    FontPathElementPtr	*fpep;{    FontEntryPtr    result = NULL;    FontScaledPtr   scaled;    FontScalableExtraPtr   extra;    int i;    extra = entry->u.scalable.extra;    for (i = 0; i < extra->numScaled; i++)    {	double rescale_x;	scaled = &extra->scaled[i];	if (!scaled->bitmap)	    continue;	if (!ComputeScaleFactors(&scaled->vals, vals, dxp, dyp, sdxp, sdyp,				 &rescale_x))	    continue;	*best = scaled->vals;	*fpep = fpe;	result = scaled->bitmap;	if (rescale_x != 1.0)	{	    /* We have rescaled horizontally due to an XLFD width field.  Change	       the matrix appropriately */	    vals->pixel_matrix[0] *= rescale_x;	    vals->pixel_matrix[1] *= rescale_x;#ifdef NOTDEF	    /* This would force the pointsize and pixelsize fields in the	       FONT property to display as matrices to more accurately	       report the font being supplied.  It might also break existing	       applications that expect a single number in that field. */	    vals->values_supplied =		vals->values_supplied & ~(PIXELSIZE_MASK | POINTSIZE_MASK) |		PIXELSIZE_ARRAY;#else /* NOTDEF */	    vals->values_supplied = vals->values_supplied & ~POINTSIZE_MASK;#endif /* NOTDEF */	    /* Recompute and reround the FontScalablePtr values after	       rescaling for the new width. */	    FontFileCompleteXLFD(vals, vals);	}	break;    }    return result;}static longdoround(x)double x;{    return (x >= 0) ? (long)(x + .5) : (long)(x - .5);}static intcomputeProps(pf, wasStringProp, npf, isStringProp, nprops, xfactor, yfactor,	     sXfactor, sYfactor)    FontPropPtr pf;    char	*wasStringProp;    FontPropPtr npf;    char	*isStringProp;    unsigned int nprops;    double      xfactor, sXfactor,                yfactor, sYfactor;{    int         n;    int         count;    fontProp   *t;    double      rawfactor;    for (count = 0; nprops > 0; nprops--, pf++, wasStringProp++) {	n = sizeof(fontPropTable) / sizeof(fontProp);	for (t = fontPropTable; n && (t->atom != pf->name); n--, t++);	if (!n)	    continue;	switch (t->type) {	case scaledX:	    npf->value = doround(xfactor * (double)pf->value);	    rawfactor = sXfactor;	    break;	case scaledY:	    npf->value = doround(yfactor * (double)pf->value);	    rawfactor = sYfactor;	    break;	case unscaled:	    npf->value = pf->value;	    npf->name = pf->name;	    npf++;	    count++;	    *isStringProp++ = *wasStringProp;	    break;	}	if (t->type != unscaled)	{	    npf->name = pf->name;	    npf++;	    count++;	    npf->value = doround(rawfactor * (double)pf->value);	    npf->name = rawFontPropTable[t - fontPropTable].atom;	    npf++;	    count++;	    *isStringProp++ = *wasStringProp;	    *isStringProp++ = *wasStringProp;	}    }    return count;}static intComputeScaledProperties(sourceFontInfo, name, vals, dx, dy, sdx, sdy,			sWidth, pProps, pIsStringProp)    FontInfoPtr     sourceFontInfo;	/* the font to be scaled */    char	    *name;		/* name of resulting font */    FontScalablePtr vals;    double	    dx, sdx,		    dy, sdy;	/* scale factors in x and y directions */    long	    sWidth;	/* 1000-pixel average width */    FontPropPtr	    *pProps;	/* returns properties; preallocated */    char	    **pIsStringProp;  /* return booleans; preallocated */{    int         n;    char       *ptr1,               *ptr2;    char       *ptr3;    FontPropPtr fp;    fontProp   *fpt;    extern int  serverGeneration;    char	*isStringProp;    int		nProps;    if (fontGeneration != serverGeneration) {	initFontPropTable();	fontGeneration = serverGeneration;    }    nProps = NPROPS + 1 + sizeof(fontPropTable) / sizeof(fontProp) +			  sizeof(rawFontPropTable) / sizeof(fontProp);    fp = (FontPropPtr) xalloc(sizeof(FontPropRec) * nProps);    *pProps = fp;    if (!fp)	return 1;    isStringProp = (char *) xalloc (nProps);    *pIsStringProp = isStringProp;    if (!isStringProp)    {	xfree (fp);	return 1;    }    ptr2 = name;    for (fpt = fontNamePropTable, n = NPROPS;	 n; 	 fp++, fpt++, n--, isStringProp++)    {	if (*ptr2)	{	    ptr1 = ptr2 + 1;	    if (!(ptr2 = strchr(ptr1, '-'))) ptr2 = strchr(ptr1, '\0');	}	*isStringProp = 0;	switch (fpt->type) {	case atom:	    fp->value = MakeAtom(ptr1, ptr2 - ptr1, TRUE);	    *isStringProp = 1;	    break;	case truncate_atom:	    for (ptr3 = ptr1; *ptr3; ptr3++)		if (*ptr3 == '[')		    break;	    if (!*ptr3) ptr3 = ptr2;	    fp->value = MakeAtom(ptr1, ptr3 - ptr1, TRUE);	    *isStringProp = 1;	    break;	case pixel_size:	    fp->value = doround(vals->pixel_matrix[3]);	    break;	case point_size:	    fp->value = doround(vals->point_matrix[3] * 10.0);	    break;	case resolution_x:	    fp->value = vals->x;	    break;	case resolution_y:	    fp->value = vals->y;	    break;	case average_width:	    fp->value = vals->width;	    break;	case fontname:	    fp->value = MakeAtom(name, strlen(name), TRUE);	    *isStringProp = 1;	    break;	case raw_ascent:	    fp->value = sourceFontInfo->fontAscent * sdy;	    break;	case raw_descent:	    fp->value = sourceFontInfo->fontDescent * sdy;	    break;	case raw_pointsize:	    fp->value = (long)(72270.0 / (double)vals->y + .5);	    break;	case raw_pixelsize:	    fp->value = 1000;	    break;	case raw_average_width:	    fp->value = sWidth;	    break;	}	fp->name = fpt->atom;    }    n = NPROPS;    n += computeProps(sourceFontInfo->props, sourceFontInfo->isStringProp,		      fp, isStringProp, sourceFontInfo->nprops, dx, dy,		      sdx, sdy);    return n;}static void ScaleBitmap();static intcompute_xform_matrix(vals, dx, dy, xform, inv_xform, xmult, ymult)    FontScalablePtr	vals;    double		dx, dy, *inv_xform, *xmult, *ymult;    register double	*xform;{    double det, sintheta, costheta, tanphi;    double pixel = get_matrix_vertical_component(vals->pixel_matrix);    double pixelset = get_matrix_horizontal_component(vals->pixel_matrix);    if (pixel < EPS || pixelset < EPS) return 0;    /* Initialize the transformation matrix to the scaling factors */    xform[0] = dx / pixelset;    xform[1] = xform[2] = 0.0;    xform[3] = dy / pixel;/* Inline matrix multiply -- somewhat ugly to minimize register usage */#define MULTIPLY_XFORM(a,b,c,d) \{ \  register double aa = (a), bb = (b), cc = (c), dd = (d); \  register double temp; \  temp =     aa * xform[0] + cc * xform[1]; \  aa =       aa * xform[2] + cc * xform[3]; \  xform[1] = bb * xform[0] + dd * xform[1]; \  xform[3] = bb * xform[2] + dd * xform[3]; \  xform[0] = temp; \  xform[2] = aa; \}    /* Rescale the transformation matrix for size of source font */    MULTIPLY_XFORM(vals->pixel_matrix[0],		   vals->pixel_matrix[1],		   vals->pixel_matrix[2],		   vals->pixel_matrix[3]);    *xmult = xform[0];    *ymult = xform[3];    if (inv_xform == NULL) return 1;    /* Compute the determinant for use in inverting the matrix. */    det = xform[0] * xform[3] - xform[1] * xform[2];    /* If the determinant is tiny or zero, give up */    if (fabs(det) < EPS) return 0;    /* Compute the inverse */    inv_xform[0] = xform[3] / det;    inv_xform[1] = -xform[1] / det;    inv_xform[2] = -xform[2] / det;    inv_xform[3] = xform[0] / det;    return 1;}/* *  ScaleFont *  returns a pointer to the new scaled font, or NULL (due to AllocError). */static FontPtrScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,	  newWidthMult, newHeightMult, sWidth)    FontPtr     opf;		/* originating font */    double      widthMult;	/* glyphs width scale factor */    double      heightMult;	/* glyphs height scale factor */    double      sWidthMult;	/* scalable glyphs width scale factor */    double      sHeightMult;	/* scalable glyphs height scale factor */    FontScalablePtr	vals;    double      *newWidthMult;	/* return: X component of glyphs width				   scale factor */    double      *newHeightMult;	/* return: Y component of glyphs height				   scale factor */    long	*sWidth;	/* return: average 1000-pixel width */{    FontPtr     pf;    FontInfoPtr pfi,                opfi;    BitmapFontPtr  bitmapFont,                obitmapFont;    CharInfoPtr pci,                opci;    int         nchars;		/* how many characters in the font */    int        *scratch;    int         i;    int         glyph;    int		firstCol, lastCol, firstRow, lastRow;    double	xform[4], inv_xform[4];    double	xmult, ymult;    int		totalwidth = 0, totalchars = 0;    int		inkindex1, inkindex2;#define OLDINDEX(i) (((i)/(lastCol - firstCol + 1) + \		      firstRow - opf->info.firstRow) * \		     (opf->info.lastCol - opf->info.firstCol + 1) + \		     (i)%(lastCol - firstCol + 1) + \		     firstCol - opf->info.firstCol)    extern int  bitmapGetBitmaps();    extern int  bitmapGetExtents();    extern int  bitmapGetGlyphs();    extern int  bitmapGetMetrics();    *sWidth = 0;    opfi = &opf->info;    glyph = opf->glyph;    obitmapFont = (BitmapFontPtr) opf->fontPrivate;    bitmapFont = 0;    pf = (FontPtr) xalloc(sizeof(FontRec));    if (!pf)	goto bail;    pf->refcnt = 0;    pf->maxPrivate = -1;    pf->devPrivates = (pointer *) 0;    pf->bit = opf->bit;    pf->byte = opf->byte;    pf->glyph = opf->glyph;    pf->scan = opf->scan;    pf->get_glyphs = bitmapGetGlyphs;    pf->get_metrics = bitmapGetMetrics;    pf->unload_font = bitmapUnloadScalable;    pf->unload_glyphs = NULL;    pfi = &pf->info;    *pfi = *opfi;    /* If charset subsetting specified in vals, determine what our range       needs to be for the output font */    if (vals->nranges)    {	int i;	pfi->allExist = 0;	firstCol = 255;	lastCol = 0;	firstRow = 255;	lastRow = 0;	for (i = 0; i < vals->nranges; i++)	{	    if (vals->ranges[i].min_char_high != vals->ranges[i].max_char_high)	    {		firstCol = opfi->firstCol;		lastCol = opfi->lastCol;	    }	    if (firstCol > vals->ranges[i].min_char_low)		firstCol = vals->ranges[i].min_char_low;	    if (lastCol < vals->ranges[i].max_char_low)		lastCol = vals->ranges[i].max_char_low;	    if (firstRow > vals->ranges[i].min_char_high)		firstRow = vals->ranges[i].min_char_high;	    if (lastRow < vals->ranges[i].max_char_high)		lastRow = vals->ranges[i].max_char_high;	}	if (firstCol > lastCol || firstRow > lastRow)	    goto bail;	if (firstCol < opfi->firstCol)	    firstCol = opfi->firstCol;	if (lastCol > opfi->lastCol)	    lastCol = opfi->lastCol;	if (firstRow < opfi->firstRow)	    firstRow = opfi->firstRow;	if (lastRow > opfi->lastRow)	    lastRow = opfi->lastRow;    }    else    {	firstCol = opfi->firstCol;	lastCol = opfi->lastCol;	firstRow = opfi->firstRow;	lastRow = opfi->lastRow;    }    bitmapFont = (BitmapFontPtr) xalloc(sizeof(BitmapFontRec));    if (!bitmapFont)	goto bail;    nchars = (lastRow - firstRow + 1) * (lastCol - firstCol + 1);    pfi->firstRow = firstRow;    pfi->lastRow = lastRow;    pfi->firstCol = firstCol;    pfi->lastCol = lastCol;

⌨️ 快捷键说明

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