[XeTeX] xdv2pdf vs xdvipdfmx
Oleg Parashchenko
olpa at uucode.com
Mon Jan 31 10:32:13 CET 2011
Hello Will,
On Sat, 29 Jan 2011 20:30:16 +1030
Will Robertson <wspr81 at gmail.com> wrote:
...
> > (Starting with 10.5, Mac OS X provides a font-from-file function.
> > A test code does work under my 10.6.)
>
> How does this work? Can you show an example?
Yes, see below. Disclamer: it is my first experience in Mac OS X
programming, and I did not care to release resources.
Use:
1) $ ./PdfHelloWorldEffects
File "hello.pdf" contains "hello", font Times-roman, blue color.
2) $ ./PdfHelloWorldEffects punknova-regular.otf
Font "punknova-regular.otf", blue color
3) $ ./PdfHelloWorldEffects
punknova-regular.otf /System/Library/Filters/Black \ \&\ White.qfilter
Font "punknova-regular.otf", black color due to application of Quartz
Filter "Black & White".
///// --- cut here ---
#include <stdio.h>
#include <CoreFoundation/CoreFoundation.h>
#include <ApplicationServices/ApplicationServices.h>
#import <QuartzFilters/QuartzFilters.h>
extern bool CGFontGetGlyphsForUnichars(CGFontRef, UniChar[], CGGlyph[],
size_t);
int main (int argc, const char * argv[]) {
CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
CFSTR("hello.pdf"), kCFURLPOSIXPathStyle, FALSE);
const CGRect mediaRect = CGRectMake(0, 0, 100, 100);
CGContextRef pdfContext = CGPDFContextCreateWithURL(url, &mediaRect,
NULL); CGContextBeginPage (pdfContext, &mediaRect);
//
// Set color
//
CGColorRef color = CGColorCreateGenericRGB(0., 0., 1., 1.);
CGContextSetFillColorWithColor(pdfContext, color);
CGContextSetStrokeColorWithColor(pdfContext, color);
//
// Select and set font
//
CGFontRef font;
if (argc < 2) {
font = CGFontCreateWithFontName(CFSTR("Times-Roman"));
} else {
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithFilename
(argv[1]);
font = CGFontCreateWithDataProvider(fontDataProvider);
CGDataProviderRelease(fontDataProvider);
}
CGContextSetFont(pdfContext, font);
CGContextSetFontSize(pdfContext, 24);
//
// Apply a quartz filter
//
if (argc > 2) {
NSString *qfilter = [[NSString alloc] initWithUTF8String:argv[2]];
NSURL *url = [NSURL fileURLWithPath:qfilter];
QuartzFilter *qf = [QuartzFilter quartzFilterWithURL:url];
[qf applyToContext:pdfContext];
}
//
// Print "hello"
//
CGGlyph glyphs[5];
UniChar hello[] = {'H', 'e', 'l', 'l', 'o'};
CGFontGetGlyphsForUnichars(font, hello, glyphs, 5);
CGContextShowGlyphsAtPoint(pdfContext, 10, 50, glyphs, 5);
CGContextEndPage(pdfContext);
CGContextRelease(pdfContext);
CFRelease(url);
return 0;
}
///// --- cut here ---
>
> Best wishes,
> Will
>
>
>
>
> --------------------------------------------------
> Subscriptions, Archive, and List information, etc.:
> http://tug.org/mailman/listinfo/xetex
>
--
Oleg Parashchenko olpa@ http://uucode.com/
http://uucode.com/blog/ XML, TeX, Python, Mac, Chess
More information about the XeTeX
mailing list