int MapCharToGlyph_AAT(ATSUStyle style, UInt32 ch) { UniChar txt[2]; int len = 1; if (sTextLayout == 0) InitializeLayout(); if (ch > 0xffff) { ch -= 0x10000; txt[0] = 0xd800 + ch / 1024; txt[1] = 0xdc00 + ch % 1024; len = 2; } else txt[0] = ch; OSStatus status = ATSUSetTextPointerLocation(sTextLayout, &txt[0], 0, len, len); if (status != noErr) return 0; status = ATSUSetRunStyle(sTextLayout, style, 0, len); if (status != noErr) return 0; ByteCount bufferSize = sizeof(ATSUGlyphInfoArray); ATSUGlyphInfoArray info; status = ATSUGetGlyphInfo(sTextLayout, 0, len, &bufferSize, &info); if (status == noErr) { if (bufferSize > 0 && info.numGlyphs > 0) return info.glyphs[0].glyphID; } return 0; }
MainWindow::MainWindow(ChessBoard& board) : board(board){ startPiece = NULL; startX = 0; startY = 0; currentPlayer = WHITE; promotion = false; gameOver = false; setFixedSize(480, 480); InitializeLayout(); }
void DoAtsuiLayout(void* p, int justify) { memoryword* node = (memoryword*)p; unsigned f = native_font(node); if (fontarea[f] != AAT_FONT_FLAG) { fprintf(stderr, "internal error: do_atsui_layout called for non-ATSUI font\n"); exit(1); } if (sTextLayout == 0) InitializeLayout(); OSStatus status = noErr; long txtLen = native_length(node); const UniChar* txtPtr = (UniChar*)(node + native_node_size); status = ATSUSetTextPointerLocation(sTextLayout, txtPtr, 0, txtLen, txtLen); // we're using this font in AAT mode, so fontlayoutengine[f] is actually an ATSUStyle ATSUStyle style = (ATSUStyle)(fontlayoutengine[native_font(node)]); status = ATSUSetRunStyle(sTextLayout, style, 0, txtLen); ATSUAttributeTag tags[] = { kATSULineWidthTag, kATSULineJustificationFactorTag }; ItemCount numTags = sizeof(tags) / sizeof(ATSUAttributeTag); if (justify) { ByteCount valSizes[] = { sizeof(Fixed), sizeof(Fract) }; Fixed wid = FixedTeXtoPSPoints(node_width(node)); Fract just = fract1; ATSUAttributeValuePtr valPtrs[] = { &wid, &just }; status = ATSUSetLayoutControls(sTextLayout, numTags, tags, valSizes, valPtrs); } ItemCount count; ATSLayoutRecord* layoutRec = NULL; status = ATSUDirectGetLayoutDataArrayPtrFromTextLayout(sTextLayout, 0, kATSUDirectDataLayoutRecordATSLayoutRecordCurrent, (void*)&layoutRec, &count); int i; int realGlyphCount = 0; int lastRealGlyph = 0; for (i = 0; i < count; ++i) if (layoutRec[i].glyphID < 0xfffe) { lastRealGlyph = i; ++realGlyphCount; } void* glyph_info = xmalloc(realGlyphCount * native_glyph_info_size); FixedPoint* locations = (FixedPoint*)glyph_info; UInt16* glyphIDs = (UInt16*)(locations + realGlyphCount); Fixed lsUnit = justify ? 0 : fontletterspace[f]; Fixed lsDelta = 0; realGlyphCount = 0; for (i = 0; i < count; ++i) { if (layoutRec[i].glyphID < 0xfffe) { if ((layoutRec[i].flags & kATSGlyphInfoIsAttachment) && (lsDelta != 0)) lsDelta -= lsUnit; glyphIDs[realGlyphCount] = layoutRec[i].glyphID; locations[realGlyphCount].y = 0; /* FIXME: won't handle baseline offsets */ locations[realGlyphCount].x = FixedPStoTeXPoints(layoutRec[i].realPos) + lsDelta; lsDelta += lsUnit; ++realGlyphCount; } } if (lsDelta != 0) lsDelta -= lsUnit; native_glyph_count(node) = realGlyphCount; native_glyph_info_ptr(node) = glyph_info; if (!justify) node_width(node) = FixedPStoTeXPoints(layoutRec[count-1].realPos) + lsDelta; ATSUDirectReleaseLayoutDataArrayPtr(NULL, kATSUDirectDataLayoutRecordATSLayoutRecordCurrent, (void*)&layoutRec); if (justify) ATSUClearLayoutControls(sTextLayout, numTags, tags); }