iOS平台雖然提供了方便的PDF渲染介面,但對於簡體中文字型的支援並不完整,容易發生亂碼。即使在iOS 5.0中有了一定的改善,但還是存在亂碼問題。MuPDF是一款開源的PDF閱讀器,渲染效率相對較高,並且對簡體中文字型的支援也很好。官網:http://www.mupdf.com/下載並解壓縮MuPDF的源碼後,開啟Makerules檔案,查看相關編譯規則,支援平台有不少,但是沒有mac編譯iOS平台的規則,於是添加相關規則。模擬器i386規則: CC = /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2AR = /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/arCPP = /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/cppCFLAGS += -arch i386 -m32 -pipe -mdynamic-no-pic -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -mmacosx-version-min=10.5 -I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/include/
-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdkLDFLAGS +=-arch i386 -m32 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk -Wl,-dead_strip -mmacosx-version-min=10.5CROSSCOMPILE=yesNOX11=yes真機armv6規則:CC = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2AR = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arCPP = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cppCFLAGS += -arch armv6 -pipe -mdynamic-no-pic -std=gnu99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=4.2 -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/include/libxml2
-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdkLDFLAGS += -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -miphoneos-version-min=4.2CROSSCOMPILE=yesNOX11=yes真機armv7規則:CC = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2AR = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arCPP = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cppCFLAGS += -arch armv7 -pipe -mdynamic-no-pic -std=gnu99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=4.2 -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/include/libxml2
-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdkLDFLAGS += -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -miphoneos-version-min=4.2CROSSCOMPILE=yesNOX11=yes執行make libs命令,在目錄下產生*.a庫檔案。在過程中遇見過一些問題:產生庫檔案後,在工程中調用相關介面,提示錯誤:ld: symbol(s) not found 經過排查,原來犯了個小錯誤:MuPDF是使用C編譯器編譯,但是工程使用c++編譯,所以需要在引用檔案添加extern "C" { #include <fitz.h> #include <mupdf.h>}編譯真機版庫檔案時候,提示錯誤:‘asm’ undeclared (first use in this function)進過排查,編譯參數設定錯誤,將-std=c99換成-std=gnu99就成功了。詳情可見:What's the difference between GNU99 and C99 (Clang)?
http://stackoverflow.com/questions/5313536/whats-the-difference-between-gnu99-and-c99-clang
終於木有亂碼了: