use of com.github.hmdev.info.ImageInfo in project AozoraEpub3 by hmdev.
the class Epub3Writer method getImageWidthRatio.
/** 画像の画面内の比率を取得 表示倍率指定反映後
* @return 画面幅にタイする表示比率% 倍率1の場合は0 小さい画像は-1を返す */
public double getImageWidthRatio(String srcFilePath, boolean hasCaption) {
//0なら無効
if (this.imageScale == 0)
return 0;
double ratio = 0;
try {
ImageInfo imageInfo = this.imageInfoReader.getImageInfo(srcFilePath);
if (imageInfo != null) {
//外字や数式は除外 行方向に64px以下
if (this.bookInfo.vertical) {
if (imageInfo.getWidth() <= 64)
return -1;
} else if (imageInfo.getHeight() <= 64)
return -1;
//回転時は縦横入れ替え
int imgW = imageInfo.getWidth();
int imgH = imageInfo.getHeight();
if (imageInfo.rotateAngle == 90 || imageInfo.rotateAngle == 270) {
imgW = imageInfo.getHeight();
imgH = imageInfo.getWidth();
}
double wRatio = (double) imgW / this.dispW * this.imageScale * 100;
double hRatio = (double) imgH / this.dispH * this.imageScale * 100;
//縦がはみ出ている場合は調整
if (hasCaption) {
//キャプションがある場合は高さを90%にする
if (hRatio >= 90) {
wRatio *= 100 / hRatio;
wRatio *= 0.9;
}
} else if (hRatio >= 100) {
wRatio *= 100 / hRatio;
}
ratio = wRatio;
}
} catch (Exception e) {
e.printStackTrace();
}
return Math.min(100, ratio);
}
Aggregations