feat: 优化代码

pull/132/head
kunfei 5 years ago
parent 4b78557bbb
commit e32cfc03e7
  1. 1
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  3. 19
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt

@ -254,6 +254,7 @@ object ReadBookConfig {
var lineSpacingExtra: Int = 12,//行间距 var lineSpacingExtra: Int = 12,//行间距
var paragraphSpacing: Int = 12,//段距 var paragraphSpacing: Int = 12,//段距
var titleMode: Int = 0,//标题居中 var titleMode: Int = 0,//标题居中
var titleLineSpacing: Int = 0,
var paddingBottom: Int = 6, var paddingBottom: Int = 6,
var paddingLeft: Int = 16, var paddingLeft: Int = 16,
var paddingRight: Int = 16, var paddingRight: Int = 16,

@ -81,6 +81,8 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
dsb_text_letter_spacing.valueFormat = { dsb_text_letter_spacing.valueFormat = {
((it - 50) / 100f).toString() ((it - 50) / 100f).toString()
} }
dsb_line_size.valueFormat = { (it / 10f).toString() }
dsb_paragraph_spacing.valueFormat = { (it / 10f).toString() }
} }
private fun initData() { private fun initData() {

@ -13,10 +13,7 @@ import io.legado.app.help.ReadBookConfig
import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextChapter
import io.legado.app.ui.book.read.page.entities.TextLine import io.legado.app.ui.book.read.page.entities.TextLine
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.utils.dp import io.legado.app.utils.*
import io.legado.app.utils.getPrefString
import io.legado.app.utils.removePref
import io.legado.app.utils.toStringArray
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@ -111,14 +108,14 @@ object ChapterProvider {
val textLine = TextLine(isTitle = isTitle) val textLine = TextLine(isTitle = isTitle)
if (durY + textPaint.textHeight < visibleHeight) { if (durY + textPaint.textHeight < visibleHeight) {
textPages.last().textLines.add(textLine) textPages.last().textLines.add(textLine)
durY += textPaint.textHeight + lineSpacingExtra durY += textPaint.textHeight * lineSpacingExtra / 10f
} else { } else {
textPages.last().text = stringBuilder.toString() textPages.last().text = stringBuilder.toString()
stringBuilder.clear() stringBuilder.clear()
pageLines.add(textPages.last().textLines.size) pageLines.add(textPages.last().textLines.size)
pageLengths.add(textPages.last().text.length) pageLengths.add(textPages.last().text.length)
//新建页面 //新建页面
durY = textPaint.textHeight + lineSpacingExtra durY = textPaint.textHeight * lineSpacingExtra / 10f
textPages.add(TextPage()) textPages.add(TextPage())
textPages.last().textLines.add(textLine) textPages.last().textLines.add(textLine)
} }
@ -144,7 +141,7 @@ object ChapterProvider {
addCharsToLineMiddle(textLine, words, textPaint, desiredWidth, 0f) addCharsToLineMiddle(textLine, words, textPaint, desiredWidth, 0f)
} }
} }
durY += paragraphSpacing durY += textPaint.textHeight * paragraphSpacing / 10f
return durY return durY
} }
@ -273,10 +270,10 @@ object ChapterProvider {
val bold = if (ReadBookConfig.textBold) Typeface.BOLD else Typeface.NORMAL val bold = if (ReadBookConfig.textBold) Typeface.BOLD else Typeface.NORMAL
contentPaint.typeface = Typeface.create(typeface, bold) contentPaint.typeface = Typeface.create(typeface, bold)
//间距 //间距
lineSpacingExtra = ReadBookConfig.lineSpacingExtra.dp lineSpacingExtra = ReadBookConfig.lineSpacingExtra
paragraphSpacing = ReadBookConfig.paragraphSpacing.dp paragraphSpacing = ReadBookConfig.paragraphSpacing
titlePaint.textSize = (ReadBookConfig.textSize + 2).dp.toFloat() titlePaint.textSize = (ReadBookConfig.textSize + 2).sp.toFloat()
contentPaint.textSize = ReadBookConfig.textSize.dp.toFloat() contentPaint.textSize = ReadBookConfig.textSize.sp.toFloat()
upSize() upSize()
} }

Loading…
Cancel
Save