From 622bf4a7c90729be28a038c49e4c237ce9f31297 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Wed, 26 Jul 2006 16:19:45 +0000 Subject: added main xetex source directory git-svn-id: svn://tug.org/texlive/trunk@1920 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/web2c/xetexdir/XeTeX_pic.c | 111 +++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Build/source/texk/web2c/xetexdir/XeTeX_pic.c (limited to 'Build/source/texk/web2c/xetexdir/XeTeX_pic.c') diff --git a/Build/source/texk/web2c/xetexdir/XeTeX_pic.c b/Build/source/texk/web2c/xetexdir/XeTeX_pic.c new file mode 100644 index 00000000000..a511b848038 --- /dev/null +++ b/Build/source/texk/web2c/xetexdir/XeTeX_pic.c @@ -0,0 +1,111 @@ +/****************************************************************************\ + Part of the XeTeX typesetting system + copyright (c) 1994-2005 by SIL International + written by Jonathan Kew + + This software is distributed under the terms of the Common Public License, + version 1.0. + For details, see or the file + cpl1.0.txt included with the software. +\****************************************************************************/ + +/* +XeTeX_pic.c + interface between xetex and graphics files + (not used on OS X -- we use QuickTime graphics importers instead) + only needs to get image dimensions, not actually load/process the file +*/ + +#define EXTERN extern +#include "xetexd.h" + +#include "XeTeX_ext.h" + +#include +#include +#include +#include +#include + +#include "pdfimage.h" +#include "pngimage.h" +#include "jpegimage.h" +#include "bmpimage.h" + +/* + locate picture file from /nameoffile+1/ using kpathsearch + pdfBoxType indicates which pdf bounding box to use (0 for \XeTeXpicfile) + page indicates which page is wanted (0-based) + return 0 for success, or non-zero error code for failure + return full path in *path + return bounds (tex points) in *bounds +*/ +int +find_pic_file(char** path, realrect* bounds, int pdfBoxType, int page) +{ + int err = -1; + FILE* fp = NULL; + char* pic_path = kpse_find_file((char*)nameoffile + 1, kpse_pict_format, 1); + + *path = NULL; + bounds->x = bounds->y = bounds->wd = bounds->ht = 0.0; + + if (pic_path == NULL) + goto done; + + /* if cmd was \XeTeXpdffile, use xpdflib to read it */ + if (pdfBoxType != 0) { + err = pdf_get_rect(pic_path, page, pdfBoxType, bounds); + goto done; + } + + /* otherwise try graphics formats that we know */ + fp = fopen(pic_path, FOPEN_RBIN_MODE); + if (fp == NULL) + goto done; + + if (check_for_jpeg(fp)) { + struct JPEG_info info; + err = JPEG_scan_file(&info, fp); + if (err == 0) { + bounds->wd = (info.width * 72.27) / info.xdpi; + bounds->ht = (info.height * 72.27) / info.ydpi; + } + goto done; + } + + if (check_for_bmp(fp)) { + struct bmp_info info; + err = bmp_scan_file(&info, fp); + if (err == 0) { + bounds->wd = (info.width * 72.27) / info.xdpi; + bounds->ht = (info.height * 72.27) / info.ydpi; + } + goto done; + } + + if (check_for_png(fp)) { + struct png_info info; + err = png_scan_file(&info, fp); + if (err == 0) { + bounds->wd = (info.width * 72.27) / info.xdpi; + bounds->ht = (info.height * 72.27) / info.ydpi; + } + goto done; + } + + /* could support other file types here (TIFF, WMF, etc?) */ + +done: + if (fp != NULL) + fclose(fp); + + if (err == 0) + *path = pic_path; + else { + if (pic_path != NULL) + free(pic_path); + } + + return err; +} -- cgit v1.2.3