Search in sources :

Example 11 with ImageInfo

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);
}
Also used : ImageInfo(com.github.hmdev.info.ImageInfo) IOException(java.io.IOException)

Aggregations

ImageInfo (com.github.hmdev.info.ImageInfo)11 IOException (java.io.IOException)7 ZipArchiveEntry (org.apache.commons.compress.archivers.zip.ZipArchiveEntry)5 BufferedInputStream (java.io.BufferedInputStream)4 SectionInfo (com.github.hmdev.info.SectionInfo)3 RarException (com.github.junrar.exception.RarException)3 BufferedWriter (java.io.BufferedWriter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileInputStream (java.io.FileInputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 ZipArchiveInputStream (org.apache.commons.compress.archivers.zip.ZipArchiveInputStream)3 ChapterLineInfo (com.github.hmdev.info.ChapterLineInfo)2 Archive (com.github.junrar.Archive)2 FileHeader (com.github.junrar.rarfile.FileHeader)2 InputStream (java.io.InputStream)2 ArchiveEntry (org.apache.commons.compress.archivers.ArchiveEntry)2 BookInfo (com.github.hmdev.info.BookInfo)1 ChapterInfo (com.github.hmdev.info.ChapterInfo)1 GaijiInfo (com.github.hmdev.info.GaijiInfo)1