0

I need to draw a text line where some specified characters would be replaced by arbitrary polygons. These polygons must be painted with Graphics directly using drawPolygon. method. While Unicode contains a range of graphical symbols, they are not appropriate for this task.

I was wondering if it was possible to replace a character with a polygon, in any instance of that character's occurrence in a string? For example, if I typed-in the word 'Holly' and hit 'enter', the first letter would be replaced by the polygon. If I then went to type the word 'thistle', the polygon's new position would be in place of the second letter?

Any help/guidance will be greatly appreciated.

4

3 に答える 3

1

実際のポリゴンが Unicode で表現されていると仮定すると、文字列を置き換えるだけで済みます。

System.out.println("Hello".replace('H', '\u25C6'));

生産する

◆エロ

于 2013-02-02T21:51:43.533 に答える
0

ポリゴンを表示したい場合は、Unicode シンボルを選択するのが簡単な方法かもしれません。グラフィック コンテンツを含むものがたくさんあります (雪だるまも)

于 2013-02-02T21:38:39.803 に答える
0

これは、指定されたフォントで印刷された文字列の寸法を測定できるFontMetricsで完全に実行可能です。FontMetrics を使用して文字列フラグメントの位置を計算し、その間に文字列フラグメントとポリゴンを描画します。

このアプローチは、多角形が何らかの形で非常に特別なものでなければならない場合 (おそらく非 Unicode 文字?)、または必要な寸法が使用されているフォントの文字の寸法と大きく異なる場合に妥当と思われます。

Unicode のサポートがまだ十分ではなかった Java の初期の頃、サポートされていない国別文字をそのように描画することは珍しくありませんでした。

于 2013-02-02T21:52:51.140 に答える