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

📄 bitscale.c

📁 远程桌面连接工具
💻 C
📖 第 1 页 / 共 4 页
字号:
		    dstptr += width + 1;		    sum -= srcptr[-top_height * (width + 1)];		    srcptr += width + 1;		}		/* Done with the column... copy dest back over source */		dstptr = char_grayscale + col;		srcptr = char_grayscale + width;	 /* scratch */		for (row = 0; row < height; row++)		{		    *dstptr = *srcptr;		    dstptr += width + 1;		    srcptr += width + 1;		}	    }	}	/* Increase the grayvalue to increase ink a bit */	srcptr = char_grayscale;	for (row = 0; row < height; row++)	{	    for (col = 0; col < width; col++)	    {		register int pixvalue = (int)*srcptr * pixmult / 256;		if (pixvalue > 255) pixvalue = 255;		*srcptr = pixvalue;		srcptr++;	    }	    srcptr++;	}    }    /* Compute the increment values for the resampling loop */    TRANSFORM_POINT(inv_xform, 1, 0, point);    deltaX = (INT32)(point[0] * 65536.0);    deltaY = (INT32)(-point[1] * 65536.0);    /* Resampling loop:  resamples original glyph for generation of new       glyph in transformed coordinate system. */    for (row = 0; row < newHeight; row++)    {	/* Compute inverse transformation for start of this row */	TRANSFORM_POINT(inv_xform,			(double)(pci->metrics.leftSideBearing) + .5,			(double)(pci->metrics.ascent - row) - .5,			point);	/* Adjust for coordinate system to get resampling point */	point[0] -= opci->metrics.leftSideBearing;	point[1] = opci->metrics.ascent - point[1];	/* Convert to integer coordinates */	xValue = (INT32)(point[0] * 65536.0);	yValue = (INT32)(point[1] * 65536.0);	if (char_grayscale)	{	    INT32 *temp;	    for (col = 0; col < newWidth; col++)	    {		register int x = xValue >> 16, y = yValue >> 16;		int pixvalue, error;    		pixvalue = ((x >= 0 && x < width && y >= 0 && y < height) ?			    char_grayscale[x + y * (width + 1)] : 0) +			   thisrow[col] / 16;		if (pixvalue > 255) pixvalue = 255;		else if (pixvalue < 0) pixvalue = 0;		/* Choose the bit value and set resulting error value */		if (pixvalue >= 128)		{		    newBitmap[(col >> 3) + row * newBpr] |= mask[col & 0x7];		    error = pixvalue - 255;		}		else		    error = -pixvalue;		/* Diffuse the error */		thisrow[col + 1] += error * 7;		nextrow[col - 1] += error * 3;		nextrow[col] += error * 5;		nextrow[col + 1] = error;		xValue += deltaX;		yValue += deltaY;	    }	    /* Add in error values that fell off either end */	    nextrow[0] += nextrow[-1];	    nextrow[newWidth - 2] += thisrow[newWidth];	    nextrow[newWidth - 1] += nextrow[newWidth];	    nextrow[newWidth] = 0;	    temp = nextrow;	    nextrow = thisrow;	    thisrow = temp;	    nextrow[-1] = nextrow[0] = 0;	}	else	{	    for (col = 0; col < newWidth; col++)	    {		register int x = xValue >> 16, y = yValue >> 16;    		if (x >= 0 && x < width && y >= 0 && y < height)		{		    /* Use point-sampling for rescaling. */		    if (bitmap[(x >> 3) + y * bpr] & mask[x & 0x7])			newBitmap[(col >> 3) + row * newBpr] |= mask[col & 0x7];		}		xValue += deltaX;		yValue += deltaY;	    }	}    }    if (char_grayscale)    {	xfree(char_grayscale);	xfree(diffusion_workspace);    }}static FontPtrBitmapScaleBitmaps(pf, opf, widthMult, heightMult, vals)    FontPtr     pf;		/* scaled font */    FontPtr     opf;		/* originating font */    double      widthMult;	/* glyphs width scale factor */    double      heightMult;	/* glyphs height scale factor */    FontScalablePtr	vals;{    register int i;    int		nchars;    char       *glyphBytes;    BitmapFontPtr  bitmapFont,		   obitmapFont;    CharInfoPtr pci,		opci;    FontInfoPtr pfi;    int         glyph;    unsigned    bytestoalloc = 0;    int		firstCol, lastCol, firstRow, lastRow;    double	xform[4], inv_xform[4];    double	xmult, ymult;    bitmapFont = (BitmapFontPtr) pf->fontPrivate;    obitmapFont = (BitmapFontPtr) opf->fontPrivate;    if (!compute_xform_matrix(vals, widthMult, heightMult, xform,			      inv_xform, &xmult, &ymult))	goto bail;    pfi = &pf->info;    firstCol = pfi->firstCol;    lastCol = pfi->lastCol;    firstRow = pfi->firstRow;    lastRow = pfi->lastRow;    nchars = (lastRow - firstRow + 1) * (lastCol - firstCol + 1);    glyph = pf->glyph;    for (i = 0; i < nchars; i++)    {	if (pci = bitmapFont->encoding[i])	    bytestoalloc += BYTES_FOR_GLYPH(pci, glyph);    }    /* Do we add the font malloc stuff for VALUE ADDED ? */    /* Will need to remember to free in the Unload routine */    bitmapFont->bitmaps = (char *) xalloc(bytestoalloc);    if (!bitmapFont->bitmaps)	goto bail;    bzero(bitmapFont->bitmaps, bytestoalloc);    glyphBytes = bitmapFont->bitmaps;    for (i = 0; i < nchars; i++)    {	if ((pci = bitmapFont->encoding[i]) &&	    (opci = obitmapFont->encoding[OLDINDEX(i)]))	{	    pci->bits = glyphBytes;	    ScaleBitmap (pf, opci, pci, inv_xform,			 widthMult, heightMult);	    glyphBytes += BYTES_FOR_GLYPH(pci, glyph);	}    }    return pf;bail:    if (pf)	xfree(pf);    if (bitmapFont) {	xfree(bitmapFont->metrics);	xfree(bitmapFont->ink_metrics);	xfree(bitmapFont->bitmaps);	xfree(bitmapFont->encoding);    }    return NULL;}static FontPtrPrinterScaleBitmaps(pf, opf, widthMult, heightMult, vals)    FontPtr     pf;		/* scaled font */    FontPtr     opf;		/* originating font */    double      widthMult;	/* glyphs width scale factor */    double      heightMult;	/* glyphs height scale factor */    FontScalablePtr	vals;{    register int i;    int		nchars;    char       *glyphBytes;    BitmapFontPtr  bitmapFont,		   obitmapFont;    CharInfoPtr pci,		opci;    FontInfoPtr pfi;    int         glyph;    unsigned    bytestoalloc = 0;    int		firstCol, lastCol, firstRow, lastRow;    double	xform[4], inv_xform[4];    double	xmult, ymult;    bitmapFont = (BitmapFontPtr) pf->fontPrivate;    obitmapFont = (BitmapFontPtr) opf->fontPrivate;    if (!compute_xform_matrix(vals, widthMult, heightMult, xform,			      inv_xform, &xmult, &ymult))	goto bail;    pfi = &pf->info;    firstCol = pfi->firstCol;    lastCol = pfi->lastCol;    firstRow = pfi->firstRow;    lastRow = pfi->lastRow;    nchars = (lastRow - firstRow + 1) * (lastCol - firstCol + 1);    glyph = pf->glyph;    for (i = 0; i < nchars; i++)    {	if (pci = bitmapFont->encoding[i])	    bytestoalloc = MAX(bytestoalloc,BYTES_FOR_GLYPH(pci, glyph));    }    /* Do we add the font malloc stuff for VALUE ADDED ? */    /* Will need to remember to free in the Unload routine */    bitmapFont->bitmaps = (char *) xalloc(bytestoalloc);    if (!bitmapFont->bitmaps)	goto bail;    bzero(bitmapFont->bitmaps, bytestoalloc);    glyphBytes = bitmapFont->bitmaps;    for (i = 0; i < nchars; i++)    {	if ((pci = bitmapFont->encoding[i]) &&	    (opci = obitmapFont->encoding[OLDINDEX(i)]))	{	    pci->bits = glyphBytes;	}    }    return pf;bail:    if (pf)	xfree(pf);    if (bitmapFont) {	xfree(bitmapFont->metrics);	xfree(bitmapFont->ink_metrics);	xfree(bitmapFont->bitmaps);	xfree(bitmapFont->encoding);    }    return NULL;}#ifdef NOTDEF/* *	exported interfaces */FontFileLoadName(dirs, ndirs, name, pfont, format, fmask)    FontFileDirPtr *dirs;    int         ndirs;    char       *name;    FontPtr    *pfont;    fsBitmapFormat format;    fsBitmapFormatMask fmask;{    FontFileNamePtr fname;    char        full_name[1024];    int         ret = BadFontName;    int         i;    i = 0;    while (i < ndirs) {	if (fname = FontFileFindNameInDir(dirs[i], name)) {	    if (!fname->alias) {		if (!fname->font) {		    strcpy(full_name, dirs[i]->dir);		    strcat(full_name, fname->file);		    ret = FontFileLoad(pfont, full_name, format, fmask);		    if (ret == Successful) {			fname->font = *pfont;			(*pfont)->fpePrivate = (pointer) fname;		    }		    return ret;		}		*pfont = fname->font;		return Successful;	    }	    name = fname->file;	    i = 0;	} else	    i++;    }    return BadFontName;}#endif/* ARGSUSED */BitmapOpenScalable (fpe, pFont, flags, entry, fileName, vals, format, fmask,		    non_cachable_font)    FontPathElementPtr	fpe;    FontPtr		*pFont;    int			flags;    FontEntryPtr	entry;    char		*fileName;  /* unused */    FontScalablePtr	vals;    fsBitmapFormat	format;    fsBitmapFormatMask	fmask;    FontPtr		non_cachable_font;	/* We don't do licensing */{    FontScalableRec	best;    FontPtr		font = NullFont;    double		dx, sdx,			dy, sdy,			savedX, savedY;    FontPropPtr		props;    char		*isStringProp;    int			propCount;    int			status;    long		sWidth;    FontEntryPtr	scaleFrom;    FontPathElementPtr	scaleFPE;    FontPtr		sourceFont;    char		fontName[MAXFONTNAMELEN];    /* Can't deal with mix-endian fonts yet */#ifdef NOTDEF /* XXX need better test */    if ((format & BitmapFormatByteOrderMask) !=	    (format & BitmapFormatBitOrderMask))	return NullFontFileName;#endif    /* Reject outrageously small font sizes to keep the math from       blowing up. */    if (get_matrix_vertical_component(vals->pixel_matrix) < 1.0 ||	get_matrix_horizontal_component(vals->pixel_matrix) < 1.0)	return BadFontName;    scaleFrom = (*find_scale[BitmapGetRenderIndex(entry->u.bitmap.renderer)]) 		    (fpe, entry, vals, &best, &dx, &dy, &sdx, &sdy, &scaleFPE);    if (!scaleFrom)	return BadFontName;    status = FontFileOpenBitmap(scaleFPE, &sourceFont, LoadAll, scaleFrom,				format, fmask);    if (status != Successful)	return BadFontName;    if (!vals->width)	vals->width = best.width * dx;    /* Compute the scaled font */    savedX = dx;    savedY = dy;    font = ScaleFont(sourceFont, dx, dy, sdx, sdy, vals, &dx, &dy, &sWidth);    if (font)	font = (*scale[ BitmapGetRenderIndex(entry->u.bitmap.renderer) ]) 			(font, sourceFont, savedX, savedY, vals);    if (!font)    {	if (!sourceFont->refcnt)	    FontFileCloseFont((FontPathElementPtr) 0, sourceFont);	return AllocError;    }    /* Prepare font properties for the new font */    strcpy (fontName, scaleFrom->name.name);    FontParseXLFDName (fontName, vals, FONT_XLFD_REPLACE_VALUE);    propCount = ComputeScaledProperties(&sourceFont->info, fontName, vals,					dx, dy, sdx, sdy, sWidth, &props,					&isStringProp);    if (!sourceFont->refcnt)	FontFileCloseFont((FontPathElementPtr) 0, sourceFont);    if (propCount && (!props || !isStringProp))    {	font->info.nprops = 0;	font->info.props = (FontPropPtr)0;	font->info.isStringProp = (char *)0;	bitmapUnloadScalable(font);	return AllocError;    }    font->info.props = props;    font->info.nprops = propCount;    font->info.isStringProp = isStringProp;    *pFont = font;    return Successful;}BitmapGetInfoScalable (fpe, pFontInfo, entry, fontName, fileName, vals)    FontPathElementPtr	fpe;    FontInfoPtr		pFontInfo;    FontEntryPtr	entry;    FontNamePtr		fontName;    char		*fileName;    FontScalablePtr	vals;{    FontPtr pfont;    int flags = 0;    long format = 0;  /* It doesn't matter what format for just info */    long fmask = 0;    int ret;    ret = BitmapOpenScalable(fpe, &pfont, flags, entry, fileName, vals,			     format, fmask, NULL);    if (ret != Successful)        return ret;    *pFontInfo = pfont->info;    pfont->info.props = NULL;    pfont->info.isStringProp = NULL;    (*pfont->unload_font)(pfont);    return Successful;}voidbitmapUnloadScalable (pFont)    FontPtr	    pFont;{    BitmapFontPtr   bitmapFont;    FontInfoPtr	    pfi;    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;    pfi = &pFont->info;    xfree (pfi->props);    xfree (pfi->isStringProp);    xfree (bitmapFont->encoding);    xfree (bitmapFont->bitmaps);    xfree (bitmapFont->ink_metrics);    xfree (bitmapFont->metrics);    xfree (pFont->fontPrivate);    xfree (pFont->devPrivates);    xfree (pFont);}

⌨️ 快捷键说明

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