Xcode 4.2를 사용하여 Mac OS X (10.7) 용 간단한 코코아 응용 프로그램을 작성했습니다. 모든 응용 프로그램은 스크롤 가능한 하위 뷰 배열을 포함하는 창을 작성합니다. 각 하위 뷰는 매우 낮은 수준의 항목을 그리는 페이지를 나타냅니다. 하위 뷰의 isFlipped 메소드는 YES를 전달하므로 모든 하위 뷰의 원점이 왼쪽 위 모서리입니다. 다양한 Core Graphics 루틴을 사용하여 필자는 선을 그려 경로를 채우고 PostScripty를 즐겁게 할 수있었습니다.CGContextShowGlyphsAtPoint()가 작동 할 때 왜 CGContextShowGlyphsAtPositions()가 작동하지 않습니까?
내가 혼란스러워하는 주어진 글꼴에서 글리프 그리기입니다.
여기에 전체 코드가 있어요, 컷 - 앤 - 붙여 넣기 하위보기의 -drawRect를 들어, 프로그램에서 : 방법 -
- (void)drawRect:(NSRect)dirtyRect
{
// Start with background color for any part of this view
[[NSColor whiteColor] set];
NSRectFill(dirtyRect);
// Drop down to Core Graphics world, ensuring there's no side-effects
context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
CGContextSaveGState(context);
{
//CGFontRef theFont = CGFontCreateWithFontName(CFSTR("American Typewriter"));
//CGContextSetFont(context, theFont);
CGContextSelectFont(context, "American Typewriter", 200, kCGEncodingMacRoman);
CGContextSetFontSize(context, 200);
// Adjust the text transform so the text doesn't draw upside down
CGContextSetTextMatrix(context, CGAffineTransformScale(CGAffineTransformIdentity, 1, -1));
CGContextSetTextDrawingMode(context, kCGTextFillStroke);
CGContextSetRGBFillColor(context, 0.0, .3, 0.8, 1.0);
// Find the center of view's (not dirtyRect's) bounds
// View is 612 x 792 (nominally 8.5" by 11")
CGPoint centerPoint;
CGRect bds = [self bounds];
centerPoint.x = bds.origin.x + bds.size.width/2;
centerPoint.y = bds.origin.y + bds.size.height/2;
// Create arrays to hold glyph IDs and the positions at which to draw them.
#define glyphCount 1 // For now, just one glyph
CGGlyph glyphs[glyphCount];
CGPoint positions[glyphCount];
glyphs[0] = 40; // Glyph ID for '@' character in above font
positions[0] = centerPoint;
// Draw above center. This works.
CGContextShowGlyphsAtPoint(context, centerPoint.x, centerPoint.y - 200.0, glyphs, glyphCount);
// Draw at center. This works.
CGContextShowGlyphsAtPoint(context, positions[0].x, positions[0].y, glyphs, glyphCount);
// Draw below center. This fails (draws nothing). Why?
positions[0].y += 200.0;
CGContextShowGlyphsAtPositions(context, glyphs, positions, glyphCount);
}
CGContextRestoreGState(context);
}
무엇 내 머리를 잡아 당겨 가지고하는 것은 처음 두 glyph- 그 CGContextShowGlyphsAtPoint()를 사용하여 그리기 호출이 예상대로 잘 작동하지만 CGContextShowGlyphsAtPositions()를 사용하는 세 번째 시도는 아무 것도 그리지 않습니다. 따라서 페이지에는 @ 기호가 두 개뿐입니다. 이 동작의 차이는 이전에 CGContextSetFont() 또는 CGContextSelectFont()를 사용했는지 여부에 달려 있지 않습니다.
두 가지 거의 완전히 다른 핵심 그래픽 글리프 그리기 루틴이있는 상태에서 약간의 숨겨진 변경이 있거나 후드 아래에서 매우 다른 것이 있어야하지만 지금까지의 모든 실험은 있다.
한숨. 난 그냥보기에서 해당 위치 배열에있는 글리프 배열을 효율적으로 그릴 싶습니다.
어떤 아이디어가 잘못 되었습니까?
감사합니다. 무슨 일이 일어나는가를 알기 위해 텍스트 매트릭스에 대한 귀하의 제안은 내가 혼란에 빠지기 위해 필요한 것이 었습니다. CGContextSetTextMatrix에 대한 호출을 제거하라는 제안은 좋지 않습니다. 아래에서 설명하겠습니다. – jsbox
그리고이 방법의 헤더 파일은 LOL에 대해 반대라고 말합니다. 고마워, 애플 : "위치는 사용자 공간에 명시되어있다" – Adam