diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | README.windows | 44 | ||||
-rw-r--r-- | apps/pdftool.c | 4 | ||||
-rw-r--r-- | base/util_gettimeofday.c | 50 | ||||
-rw-r--r-- | include/fitz/base_sysdep.h | 7 | ||||
-rw-r--r-- | makefile.msvc | 128 | ||||
-rw-r--r-- | mupdf/pdf_fontfilems.c | 124 | ||||
-rw-r--r-- | raster/render.c | 8 |
8 files changed, 304 insertions, 65 deletions
@@ -202,15 +202,13 @@ LIBS_SRC = \ ${WORLD_SRC} \ ${MUPDF_SRC} \ -PDFTOOL_APP = $(OUTDIR)/pdftool - PDFTOOL_SRC = \ ${LIBS_SRC} \ pdftool.c PDFTOOL_OBJ = $(patsubst %.c, $(OUTDIR)/FITZ_%.o, ${PDFTOOL_SRC}) PDFTOOL_APP = ${OUTDIR}/pdftool -all: inform ${OUTDIR} ${PDFTOOL_APP} ${PDFRIP_APP} +all: inform ${OUTDIR} ${PDFTOOL_APP} $(OUTDIR): @mkdir -p $(OUTDIR) diff --git a/README.windows b/README.windows new file mode 100644 index 00000000..d4b223db --- /dev/null +++ b/README.windows @@ -0,0 +1,44 @@ +Overview.
+---------
+
+This document describes how to compile mupdf natively on Windows.
+
+First, the native msvc makefile is meant as a template, not a final product.
+It only builds statically linked 'pdftool' executable. If you want to
+incorporate mupdf into your own program, you can use msvc makefile as an
+example of how to compile the code on Windows with msvc.
+
+Mupdf depends on 3 libraries that are not easily available on Windows:
+* freetype
+* libjpeg
+* zlib
+
+To make it easy, I've made those dependencies available as pre-compiled
+files. You need to download http://windevlibs.googlecode.com/files/ext.zip
+and unzip under 'ext' directory. Those are header files and static libraries
+for freetype, libjpeg and zlib.
+
+You can use your own static or dll versions of those dependencies (most likely
+that will require tweaking a makefile).
+
+Compilation.
+------------
+
+The msvc makefile is called 'makefile.msvc' and you can compile mupdf on command
+line with: 'nmake -f makefile.msvc CFG=rel' (or CFG=dbg).
+
+You need to have nmake in your path. If you have Visual Studio 2005, you can
+setup the environment by executing
+"C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat" batch
+file (assuming standard installation).
+Other versions of Visual Studio have an equivalent of this file - it's just
+named differently.
+
+The build works for me with Visual Studio 2005 SP1 but Visual Studio 2005 and
+(free) Visual Studio 2005 Express should work as well.
+
+Other versions of Visual Studio should work as well (makefile might need to
+be tweaked since some of the linker/compiler flags might have changed).
+
+The result of compilation is a 'pdftool.exe' in either 'obj-rel' or 'obj-dbg' directory.
+
diff --git a/apps/pdftool.c b/apps/pdftool.c index d1379d98..7d29e813 100644 --- a/apps/pdftool.c +++ b/apps/pdftool.c @@ -12,7 +12,11 @@ #include "fitz.h" #include "mupdf.h" +#ifdef _MSC_VER +#include <Winsock2.h> +#else #include <sys/time.h> +#endif /* * Common operations. diff --git a/base/util_gettimeofday.c b/base/util_gettimeofday.c new file mode 100644 index 00000000..6388bf92 --- /dev/null +++ b/base/util_gettimeofday.c @@ -0,0 +1,50 @@ +#include <time.h>
+#include <Winsock2.h>
+#include <windows.h>
+
+#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
+ #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
+#else
+ #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
+#endif
+
+struct timezone
+{
+ int tz_minuteswest; /* minutes W of Greenwich */
+ int tz_dsttime; /* type of dst correction */
+};
+
+int gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ FILETIME ft;
+ unsigned __int64 tmpres = 0;
+ static int tzflag = 0;
+
+ if (NULL != tv)
+ {
+ GetSystemTimeAsFileTime(&ft);
+
+ tmpres |= ft.dwHighDateTime;
+ tmpres <<= 32;
+ tmpres |= ft.dwLowDateTime;
+
+ tmpres /= 10; /*convert into microseconds*/
+ /*converting file time to unix epoch*/
+ tmpres -= DELTA_EPOCH_IN_MICROSECS;
+ tv->tv_sec = (long)(tmpres / 1000000UL);
+ tv->tv_usec = (long)(tmpres % 1000000UL);
+ }
+
+ if (NULL != tz)
+ {
+ if (!tzflag)
+ {
+ _tzset();
+ tzflag++;
+ }
+ tz->tz_minuteswest = _timezone / 60;
+ tz->tz_dsttime = _daylight;
+ }
+
+ return 0;
+}
diff --git a/include/fitz/base_sysdep.h b/include/fitz/base_sysdep.h index 4e8b1115..1610cd20 100644 --- a/include/fitz/base_sysdep.h +++ b/include/fitz/base_sysdep.h @@ -19,8 +19,12 @@ #else # define FZ_FLEX 1 # define restrict +#ifdef _MSC_VER +# define inline __inline +#else # define inline __inline__ #endif +#endif #ifdef WIN32 # define vsnprintf _vsnprintf @@ -76,3 +80,6 @@ extern int opterr, optind, optopt; extern char *optarg; #endif +#ifdef NEED_GETTIMEOFDAY +extern int gettimeofday(struct timeval *tv, struct timezone *tz); +#endif diff --git a/makefile.msvc b/makefile.msvc new file mode 100644 index 00000000..75712c1b --- /dev/null +++ b/makefile.msvc @@ -0,0 +1,128 @@ +# Set default configuration
+!if "$(CFG)"==""
+CFG=dbg
+!endif
+
+# O is directory where object and binary files go
+O = obj-$(CFG)
+
+ZLIB_DIR=ext\zlib
+FREETYPE_DIR=ext\freetype231
+JPEG_DIR=ext\jpeg
+
+CC = cl.exe
+
+CFLAGS = $(CFLAGS) /nologo /c
+# standard windows defines
+CFLAGS = $(CFLAGS) /D "WIN32" /D "_WIN32_WINNT=0x0500"
+CFLAGS = $(CFLAGS) /D "WIN32_LEAN_AND_MEAN"
+CFLAGS = $(CFLAGS) /D "_SCL_SECURE_NO_DEPRECATE" /D "_CRT_SECURE_NO_DEPRECATE"
+CFLAGS = $(CFLAGS) /D "NEED_STRLCPY" /D "NEED_STRSEP" /D "NEED_MATH" /D "NEED_GETOPT" /D "NEED_GETTIMEOFDAY"
+CFLAGS = $(CFLAGS) /D "__func__=\"\""
+
+# disable "warning C4244: 'argument' : conversion from 'foo' to 'bar', possible loss of data"
+CFLAGS = $(CFLAGS) /wd4244
+
+CFLAGS = $(CFLAGS) /W3 /GR- /EHs-c- /Zi /TC
+CFLAGS = $(CFLAGS) /Iinclude /I$(FREETYPE_DIR)\include /I$(JPEG_DIR) /I$(ZLIB_DIR)
+
+#CFLAGS = $(CFLAGS) /showIncludes
+
+LIBS = $(LIBS) advapi32.lib kernel32.lib user32.lib gdi32.lib
+
+LD = link.exe
+LDFLAGS = $(LDFLAGS) /nologo /DEBUG
+
+!if "$(CFG)"=="dbg"
+LDFLAGS = $(LDFLAGS)
+LIBS = /NODEFAULTLIB:libcmtd $(LIBS) $(FREETYPE_DIR)\freetype231mt_d.lib $(JPEG_DIR)\jpeg_ds.lib $(ZLIB_DIR)\zlib_ds.lib
+!endif
+
+!if "$(CFG)"=="rel"
+LIBS = $(LIBS) $(FREETYPE_DIR)\freetype231mt.lib $(JPEG_DIR)\jpeg_s.lib $(ZLIB_DIR)\zlib_s.lib
+LDFLAGS = $(LDFLAGS) /opt:nowin98
+LDFLAGS = $(LDFLAGS) /opt:ref /opt:icf
+!endif
+
+BASE_OBJS = \
+ $(O)\base_memory.obj $(O)\base_error.obj $(O)\base_hash.obj $(O)\base_matrix.obj \
+ $(O)\base_rect.obj $(O)\base_rune.obj $(O)\util_strlcat.obj $(O)\util_strlcpy.obj \
+ $(O)\util_strsep.obj $(O)\util_getopt.obj $(O)\util_gettimeofday.obj
+
+STREAM_OBJS = \
+ $(O)\crypt_arc4.obj $(O)\crypt_crc32.obj $(O)\crypt_md5.obj $(O)\filt_a85d.obj \
+ $(O)\filt_a85e.obj $(O)\filt_ahxd.obj $(O)\filt_ahxe.obj $(O)\filt_arc4.obj \
+ $(O)\filt_faxd.obj $(O)\filt_faxdtab.obj $(O)\filt_faxe.obj $(O)\filt_faxetab.obj \
+ $(O)\filt_flate.obj $(O)\filt_lzwd.obj $(O)\filt_lzwe.obj $(O)\filt_null.obj \
+ $(O)\filt_pipeline.obj $(O)\filt_predict.obj $(O)\filt_rld.obj $(O)\filt_rle.obj \
+ $(O)\obj_array.obj $(O)\obj_dict.obj $(O)\obj_parse.obj $(O)\obj_print.obj \
+ $(O)\obj_simple.obj $(O)\stm_buffer.obj $(O)\stm_filter.obj $(O)\stm_misc.obj \
+ $(O)\stm_open.obj $(O)\stm_read.obj $(O)\stm_write.obj $(O)\filt_dctd.obj $(O)\filt_dcte.obj
+
+RASTER_OBJS = \
+ $(O)\archx86.obj $(O)\imagescale.obj $(O)\pathfill.obj $(O)\pixmap.obj \
+ $(O)\glyphcache.obj $(O)\imageunpack.obj $(O)\pathscan.obj $(O)\porterduff.obj \
+ $(O)\imagedraw.obj $(O)\meshdraw.obj $(O)\pathstroke.obj $(O)\render.obj
+
+WORLD_OBJS = \
+ $(O)\node_misc1.obj $(O)\node_misc2.obj $(O)\node_optimize.obj $(O)\node_path.obj \
+ $(O)\node_text.obj $(O)\node_toxml.obj $(O)\node_tree.obj $(O)\res_colorspace.obj \
+ $(O)\res_font.obj $(O)\res_image.obj $(O)\res_shade.obj
+
+MUPDF_OBJS = \
+ $(O)\pdf_annot.obj $(O)\pdf_build.obj $(O)\pdf_cmap.obj $(O)\pdf_colorspace1.obj \
+ $(O)\pdf_colorspace2.obj $(O)\pdf_crypt.obj $(O)\pdf_debug.obj $(O)\pdf_doctor.obj \
+ $(O)\pdf_font.obj $(O)\pdf_fontagl.obj $(O)\pdf_fontenc.obj $(O)\pdf_function.obj \
+ $(O)\pdf_image.obj $(O)\pdf_interpret.obj $(O)\pdf_lex.obj $(O)\pdf_nametree.obj \
+ $(O)\pdf_open.obj $(O)\pdf_outline.obj $(O)\pdf_page.obj $(O)\pdf_pagetree.obj \
+ $(O)\pdf_parse.obj $(O)\pdf_pattern.obj $(O)\pdf_repair.obj $(O)\pdf_resources.obj \
+ $(O)\pdf_save.obj $(O)\pdf_shade.obj $(O)\pdf_shade1.obj $(O)\pdf_shade4.obj \
+ $(O)\pdf_store.obj $(O)\pdf_stream.obj $(O)\pdf_type3.obj $(O)\pdf_unicode.obj \
+ $(O)\pdf_xobject.obj $(O)\pdf_xref.obj $(O)\pdf_fontfilems.obj
+
+LIBS_OBJS = \
+ $(BASE_OBJS) \
+ $(STREAM_OBJS) \
+ $(RASTER_OBJS) \
+ $(WORLD_OBJS) \
+ $(MUPDF_OBJS)
+
+PDFTOOL_OBJS = $(LIBS_OBJS) $(O)\pdftool.obj
+
+PDFTOOL_APP = $(O)\pdftool.exe
+PDFTOOL_PDB = $(O)\pdftool.pdb
+PDFTOOL_MAP = $(O)\pdftool.map
+
+all: $(O) $(PDFTOOL_APP)
+
+clean: force
+ -rmdir /S /Q $(O)
+
+$(O): force
+ @if not exist $(O) mkdir $(O)
+
+$(PDFTOOL_APP): $(PDFTOOL_OBJS)
+ $(LD) $(LDFLAGS) /OUT:$(PDFTOOL_APP) /PDB:$(PDFTOOL_PDB) \
+ $(PDFTOOL_OBJS) $(LIBS) \
+ /MAP:$(PDFTOOL_MAP) \
+ /SUBSYSTEM:CONSOLE /MACHINE:X86
+
+{apps\}.c{$(O)}.obj::
+ $(CC) $(CFLAGS) /Fo$(O)\ /Fd$(O)\vc80.pdb $<
+
+{base\}.c{$(O)}.obj::
+ $(CC) $(CFLAGS) /Fo$(O)\ /Fd$(O)\vc80.pdb $<
+
+{mupdf\}.c{$(O)}.obj::
+ $(CC) $(CFLAGS) /Fo$(O)\ /Fd$(O)\vc80.pdb $<
+
+{raster\}.c{$(O)}.obj::
+ $(CC) $(CFLAGS) /Fo$(O)\ /Fd$(O)\vc80.pdb $<
+
+{stream\}.c{$(O)}.obj::
+ $(CC) $(CFLAGS) /Fo$(O)\ /Fd$(O)\vc80.pdb $<
+
+{world\}.c{$(O)}.obj::
+ $(CC) $(CFLAGS) /Fo$(O)\ /Fd$(O)\vc80.pdb $<
+
+force: ;
diff --git a/mupdf/pdf_fontfilems.c b/mupdf/pdf_fontfilems.c index 6d2e605a..d9585774 100644 --- a/mupdf/pdf_fontfilems.c +++ b/mupdf/pdf_fontfilems.c @@ -7,10 +7,10 @@ #include FT_FREETYPE_H #define SAFE_FZ_READ(file, buf, size)\ - byteread = fz_read((file), (char*)(buf), (size));\ - if(byteread<0) err = fz_ferror(file);\ - if(byteread != (size)) err = fz_throw("ioerror");\ - if(err) goto cleanup; + err = fz_read(&byteread, (file), (char*)(buf), (size)); \ + if (err) goto cleanup; \ + if (byteread != (size)) err = fz_throw("ioerror");\ + if (err) goto cleanup; #define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0]) @@ -141,9 +141,9 @@ static char *basepatterns[13] = static pdf_fontlistMS fontlistMS = { - .fontmap = nil, - .cap = 0, - .len = 0, + NULL, + 0, + 0, }; static int @@ -212,9 +212,11 @@ removeredundancy(pdf_fontlistMS *fl) } qsort(fl->fontmap,fl->len,sizeof(pdf_fontmapMS),compare); fl->len -= redundancy_count; +#if 0 for(i = 0; i < fl->len; ++i) fprintf(stdout,"%s , %s , %d\n",fl->fontmap[i].fontface, fl->fontmap[i].fontpath,fl->fontmap[i].index); +#endif } static fz_error * @@ -363,7 +365,7 @@ insertmapping(pdf_fontlistMS *fl, char *facename, char *path, int index) } static fz_error * -parseTTF(fz_file *file, int offset, int index, char *path) +parseTTF(fz_stream *file, int offset, int index, char *path) { fz_error *err = nil; int byteread; @@ -375,7 +377,6 @@ parseTTF(fz_file *file, int offset, int index, char *path) char szTemp[4096]; int found; - int pos; int i; fz_seek(file,offset,0); @@ -474,9 +475,9 @@ static fz_error * parseTTFs(char *path) { fz_error *err = nil; - fz_file *file = nil; + fz_stream *file = nil; - err = fz_openfile(&file, path, FZ_READ); + err = fz_openrfile(&file, path); if(err) goto cleanup; @@ -486,7 +487,7 @@ parseTTFs(char *path) cleanup: if(file) - fz_closefile(file); + fz_dropstream(file); return err; } @@ -496,11 +497,11 @@ parseTTCs(char *path) { fz_error *err = nil; int byteread; - fz_file *file = nil; + fz_stream *file = nil; FONT_COLLECTION fontcollectioin; - int i; + ULONG i; - err = fz_openfile(&file, path, FZ_READ); + err = fz_openrfile(&file, path); if(err) goto cleanup; @@ -542,12 +543,12 @@ parseTTCs(char *path) cleanup: if(file) - fz_closefile(file); + fz_dropstream(file); return err; } -fz_error* +static fz_error* pdf_createfontlistMS() { char szFontDir[MAX_PATH*2]; @@ -558,7 +559,7 @@ pdf_createfontlistMS() WIN32_FIND_DATA FileData; fz_error *err; - if(fontlistMS.len != 0) + if (fontlistMS.len != 0) return fz_okay; GetWindowsDirectory(szFontDir, sizeof(szFontDir)); @@ -579,23 +580,19 @@ pdf_createfontlistMS() fFinished = FALSE; while (!fFinished) { - if(!(FileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)) + if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { // Get the full path for sub directory - sprintf(szFile,"%s%s",szFontDir,FileData.cFileName); - if( szFile[strlen(szFile)-1] == 'c'|| - szFile[strlen(szFile)-1] == 'C' ) + sprintf(szFile,"%s%s", szFontDir, FileData.cFileName); + if (szFile[strlen(szFile)-1] == 'c' || szFile[strlen(szFile)-1] == 'C') { err = parseTTCs(szFile); - if(err) - goto cleanup; + // ignore error parsing a given font file } - else if( szFile[strlen(szFile)-1] == 'f'|| - szFile[strlen(szFile)-1] == 'F' ) + else if (szFile[strlen(szFile)-1] == 'f'|| szFile[strlen(szFile)-1] == 'F') { err = parseTTFs(szFile); - if(err) - goto cleanup; + // ignore error parsing a given font file } } @@ -613,13 +610,13 @@ pdf_createfontlistMS() cleanup: if(err) fz_abort(err); - return fz_okay; + return nil; } void pdf_destoryfontlistMS() { - if(fontlistMS.fontmap != nil) + if (fontlistMS.fontmap != nil) fz_free(fontlistMS.fontmap); fontlistMS.len = 0; @@ -629,33 +626,42 @@ pdf_destoryfontlistMS() fz_error * pdf_lookupfontMS(char *fontname, char **fontpath, int *index) { - pdf_fontmapMS fontmap; - pdf_fontmapMS *found = nil; - char *pattern; - int i; - - if(fontlistMS.len == 0) - return fz_throw("fonterror : no fonts in the system"); - - pattern = fontname; - for (i = 0; i < ARRAY_SIZE(basenames); i++) - if (!strcmp(fontname, basenames[i])) - pattern = basepatterns[i]; - - strlcpy(fontmap.fontface,pattern,sizeof(fontmap.fontface)); - found = localbsearch(&fontmap,fontlistMS.fontmap,fontlistMS.len, - sizeof(pdf_fontmapMS),compare); - - if(found) - { - *fontpath = found->fontpath; - *index = found->index; - } - else - { - *fontpath = fontlistMS.fontmap[0].fontpath; - *index = fontlistMS.fontmap[0].index; - } + pdf_fontmapMS fontmap; + pdf_fontmapMS *found = nil; + char *pattern; + int i; + + if (fontlistMS.len == 0) + return fz_throw("fonterror : no fonts in the system"); + + pattern = fontname; + for (i = 0; i < ARRAY_SIZE(basenames); i++) + { + if (0 == strcmp(fontname, basenames[i])) + { + pattern = basepatterns[i]; + break; + } + } + + strlcpy(fontmap.fontface,pattern,sizeof(fontmap.fontface)); + found = localbsearch(&fontmap, fontlistMS.fontmap, fontlistMS.len, sizeof(pdf_fontmapMS),compare); + +#if 0 + if (!found) + found = findlinear(&fontlistMS, &fontmap); +#endif + + if (found) + { + *fontpath = found->fontpath; + *index = found->index; + } + else + { + *fontpath = fontlistMS.fontmap[0].fontpath; + *index = fontlistMS.fontmap[0].index; + } return fz_okay; } @@ -693,10 +699,8 @@ pdf_loadbuiltinfont(pdf_font *font, char *basefont) int fterr; FT_Face face; - char *pattern; char *file; int index; - int i; error = initfontlibs(); if (error) @@ -721,8 +725,6 @@ pdf_loadsystemfont(pdf_font *font, char *basefont, char *collection) fz_error *error; int fterr; FT_Face face; - char fontname[200]; - char *style; char *file; int index; diff --git a/raster/render.c b/raster/render.c index fc649469..b9748ca8 100644 --- a/raster/render.c +++ b/raster/render.c @@ -2,11 +2,17 @@ #include "fitz-world.h" #include "fitz-draw.h" +#ifdef _MSC_VER +#define noDebug printf +#ifndef DEBUG +#define DEBUG +#endif +#else #define noDEBUG(args...) printf(args) #ifndef DEBUG #define DEBUG(args...) #endif - +#endif #define QUANT(x,a) (((int)((x) * (a))) / (a)) #define HSUBPIX 5.0 #define VSUBPIX 5.0 |