Android のプレゼンテーションから段落の境界を取得

テキストフレーム内の段落およびポーションの座標取得

Java 経由で Aspose.Slides for Android を使用すると、開発者はテキストフレームの段落コレクション内の Paragraph の矩形座標を取得できるようになりました。また、段落のポーションコレクション内のポーションの座標を取得することもできます。ポーションの座標。このトピックでは、例を用いて段落の矩形座標と、段落内のポーションの位置を取得する方法を示します。

AutoShape shape = (AutoShape)pres.getSlides().get_Item(0).getShapes().get_Item(0);
TextFrame textFrame = (TextFrame)shape.getTextFrame();
for (IParagraph paragraph : textFrame.getParagraphs()){
  for (IPortion portion : paragraph.getPortions()){
    Point2D.Float point = portion.getCoordinates();
  }
}

段落の矩形座標の取得

getRect() メソッドを使用すると、開発者は段落の境界矩形を取得できます。

Presentation pres = new Presentation("HelloWorld.pptx");
try {
    IAutoShape shape = (IAutoShape) pres.getSlides().get_Item(0).getShapes().get_Item(0);
    ITextFrame textFrame = shape.getTextFrame();
    Rectangle2D.Float rect = textFrame.getParagraphs().get_Item(0).getRect();
    System.out.println("X: " + rect.x + " Y: " + rect.y + " Width: " + rect.width + " Height: " + rect.height);
} finally {
    if (pres != null) pres.dispose();
}

テーブルセルのテキストフレーム内の段落とポーションのサイズ取得

テーブルセルのテキストフレーム内で Portion または Paragraph のサイズと座標を取得するには、IPortion.getRectIParagraph.getRect メソッドを使用できます。

このサンプルコードは上記の操作を示しています。

Presentation pres = new Presentation("source.pptx");
try {
    Table tbl = (Table)pres.getSlides().get_Item(0).getShapes().get_Item(0);
    ICell cell = tbl.getRows().get_Item(1).get_Item(1);

    double x = tbl.getX() + tbl.getRows().get_Item(1).get_Item(1).getOffsetX();
    double y = tbl.getY() + tbl.getRows().get_Item(1).get_Item(1).getOffsetY();

    for (IParagraph para : cell.getTextFrame().getParagraphs())
    {
        if (para.getText().equals(""))
            continue;

        Rectangle2D.Float rect = para.getRect();
        IAutoShape shape =
                pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle,
                        (float)rect.getX() + (float)x, (float)rect.getY() + (float)y, (float)rect.getWidth(), (float)rect.getHeight());

        shape.getFillFormat().setFillType(FillType.NoFill);
        shape.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.YELLOW);
        shape.getLineFormat().getFillFormat().setFillType(FillType.Solid);

        for (IPortion portion : para.getPortions())
        {
            if (portion.getText().contains("0"))
            {
                rect = portion.getRect();
                shape =
                        pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle,
                                (float)rect.getX() + (float)x, (float)rect.getY() + (float)y, (float)rect.getWidth(), (float)rect.getHeight());

                shape.getFillFormat().setFillType(FillType.NoFill);
            }
        }
    }
} finally {
    if (pres != null) pres.dispose();
}

FAQ

段落およびテキストポーションの座標はどの単位で返されますか?

ポイント単位です。1インチ=72ポイントです。これはスライド上のすべての座標と寸法に適用されます。

ワードラップは段落の境界に影響しますか?

はい。wrappingTextFrame で有効になっている場合、テキストは領域の幅に合わせて折り返され、段落の実際の境界が変わります。

段落の座標はエクスポートされた画像のピクセルに確実に変換できますか?

はい。ポイントをピクセルに変換するには、pixels = points × (DPI / 72) の式を使用します。結果はレンダリング/エクスポート時に選択した DPI に依存します。

スタイル継承を考慮した「実効」段落書式設定パラメータはどう取得しますか?

effective paragraph formatting data structure を使用します。これにより、インデント、間隔、ラッピング、RTL などの最終的に統合された値が返されます。