我正在尝试使用MAC从Clipboard获取字体信息。下面是从Clipboard获取值的代码。
代码
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
DataFlavor dfRTF = new DataFlavor("text/rtf", "Rich Formatted Text");
DataFlavor dfTxt = DataFlavor.stringFlavor;
boolean hasTransferableRTFText = (contents != null)
&& contents.isDataFlavorSupported(dfRTF);
boolean hasTransferableTxtText = (contents != null)
&& contents.isDataFlavorSupported(dfTxt);
if (hasTransferableRTFText) {
try {
result = streamToString((InputStream)contents.getTransferData(dfRTF));
System.out.println("dfRTF "+result);
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (hasTransferableTxtText) {
try {
result = (String)contents.getTransferData(dfTxt);
System.out.println("dfTxt "+result);
} catch (Exception ex) {
ex.printStackTrace();
}
}
并且代码返回MAC解码值如下:
dfRTF {\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural
\f0\b\fs24 \cf0 Hello WORLD}
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural
\f0\b\fs24 \cf0 Hello WORLD}
我知道它\f0\b\fs24 \cf0 Hello WORLD}
包含字体信息,\b
其中BOLD
.
我如何对其进行编码以获得该特定值,例如我想知道它是BOLDED 还是 NO。请指教。