1

TextEdit (ObjC または Carbon) で選択したテキストのフォント名を取得することはできますか? このコードを試しましたが、「値」はnullです:

AXUIElementRef systemWideElement = AXUIElementCreateSystemWide();
AXUIElementRef focussedElement = NULL;
AXError error = AXUIElementCopyAttributeValue(systemWideElement,
    kAXFocusedUIElementAttribute, (CFTypeRef*)&focussedElement);
CFTypeRef value;
AXUIElementCopyAttributeValue(focussedElement, kAXFontTextAttribute, &value);

ありがとう。

4

1 に答える 1

2

kAXFontTextAttributeAXTextAttributedString.h で宣言されていることに注意してください。UI 要素の属性ではありません。これは、属性付き文字列内のテキストの属性です。

kAXAttributedStringForRangeParameterizedAttributeで取得した値を渡して、代わりに を試してくださいkAXSelectedTextRangeAttributekAXFontTextAttribute(これは、フォーカスされた UI 要素が AXTextArea であると想定しています。それを想定しないでください。)これにより、属性によってフォント ディクショナリを取得できる AXTextAttributedString が返されます。

于 2012-05-08T07:23:45.757 に答える