|  |  | @ -12,7 +12,9 @@ import io.legado.app.constant.PreferKey | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.help.ReadBookConfig |  |  |  | import io.legado.app.help.ReadBookConfig | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.lib.theme.accentColor |  |  |  | import io.legado.app.lib.theme.accentColor | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.service.help.ReadBook |  |  |  | import io.legado.app.service.help.ReadBook | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.ui.book.read.page.entities.* |  |  |  | import io.legado.app.ui.book.read.page.entities.TextChar | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 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.provider.ChapterProvider |  |  |  | import io.legado.app.ui.book.read.page.provider.ChapterProvider | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.ui.book.read.page.provider.ImageProvider |  |  |  | import io.legado.app.ui.book.read.page.provider.ImageProvider | 
			
		
	
		
		
			
				
					
					|  |  |  | import io.legado.app.ui.book.read.page.provider.TextPageFactory |  |  |  | import io.legado.app.ui.book.read.page.provider.TextPageFactory | 
			
		
	
	
		
		
			
				
					|  |  | @ -39,7 +41,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
		
			
				
					
					|  |  |  |     private val visibleRect = RectF() |  |  |  |     private val visibleRect = RectF() | 
			
		
	
		
		
			
				
					
					|  |  |  |     private val selectStart = arrayOf(0, 0, 0) |  |  |  |     private val selectStart = arrayOf(0, 0, 0) | 
			
		
	
		
		
			
				
					
					|  |  |  |     private val selectEnd = arrayOf(0, 0, 0) |  |  |  |     private val selectEnd = arrayOf(0, 0, 0) | 
			
		
	
		
		
			
				
					
					|  |  |  |     private var textChapter: TextChapter? = null |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     var textPage: TextPage = TextPage() |  |  |  |     var textPage: TextPage = TextPage() | 
			
		
	
		
		
			
				
					
					|  |  |  |         private set |  |  |  |         private set | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -51,9 +52,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
		
			
				
					
					|  |  |  |         callBack = activity as CallBack |  |  |  |         callBack = activity as CallBack | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     fun setContent(pageData: PageData) { |  |  |  |     fun setContent(textPage: TextPage) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         this.textChapter = pageData.textChapter |  |  |  |         this.textPage = textPage | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         this.textPage = pageData.textPage |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         invalidate() |  |  |  |         invalidate() | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -140,9 +140,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
		
			
				
					
					|  |  |  |         isReadAloud: Boolean, |  |  |  |         isReadAloud: Boolean, | 
			
		
	
		
		
			
				
					
					|  |  |  |     ) { |  |  |  |     ) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         val textPaint = if (isTitle) { |  |  |  |         val textPaint = if (isTitle) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             textChapter?.titlePaint ?: ChapterProvider.titlePaint |  |  |  |             ChapterProvider.titlePaint | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } else { |  |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |             textChapter?.contentPaint ?: ChapterProvider.contentPaint |  |  |  |             ChapterProvider.contentPaint | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         textPaint.color = |  |  |  |         textPaint.color = | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (isReadAloud) context.accentColor else ReadBookConfig.textColor |  |  |  |             if (isReadAloud) context.accentColor else ReadBookConfig.textColor | 
			
		
	
	
		
		
			
				
					|  |  | @ -190,14 +190,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
		
			
				
					
					|  |  |  |             pageOffset = min(0, offset) |  |  |  |             pageOffset = min(0, offset) | 
			
		
	
		
		
			
				
					
					|  |  |  |         } else if (pageOffset > 0) { |  |  |  |         } else if (pageOffset > 0) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             pageFactory.moveToPrev(false) |  |  |  |             pageFactory.moveToPrev(false) | 
			
		
	
		
		
			
				
					
					|  |  |  |             textPage = pageFactory.curData.textPage |  |  |  |             textPage = pageFactory.curPage | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             pageOffset -= textPage.height.toInt() |  |  |  |             pageOffset -= textPage.height.toInt() | 
			
		
	
		
		
			
				
					
					|  |  |  |             upView?.invoke(textPage) |  |  |  |             upView?.invoke(textPage) | 
			
		
	
		
		
			
				
					
					|  |  |  |             contentDescription = textPage.text |  |  |  |             contentDescription = textPage.text | 
			
		
	
		
		
			
				
					
					|  |  |  |         } else if (pageOffset < -textPage.height) { |  |  |  |         } else if (pageOffset < -textPage.height) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             pageOffset += textPage.height.toInt() |  |  |  |             pageOffset += textPage.height.toInt() | 
			
		
	
		
		
			
				
					
					|  |  |  |             pageFactory.moveToNext(false) |  |  |  |             pageFactory.moveToNext(false) | 
			
		
	
		
		
			
				
					
					|  |  |  |             textPage = pageFactory.curData.textPage |  |  |  |             textPage = pageFactory.curPage | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             upView?.invoke(textPage) |  |  |  |             upView?.invoke(textPage) | 
			
		
	
		
		
			
				
					
					|  |  |  |             contentDescription = textPage.text |  |  |  |             contentDescription = textPage.text | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
	
		
		
			
				
					|  |  | @ -308,15 +308,19 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             Log.e("y", "$y") |  |  |  |             Log.e("y", "$y") | 
			
		
	
		
		
			
				
					
					|  |  |  |             for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { |  |  |  |             for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { |  |  |  |                 if (y > textLine.lineTop + relativeOffset | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     && y < textLine.lineBottom + relativeOffset | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 ) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     Log.e("line", "$relativePos  $lineIndex") |  |  |  |                     Log.e("line", "$relativePos  $lineIndex") | 
			
		
	
		
		
			
				
					
					|  |  |  |                     for ((charIndex, textChar) in textLine.textChars.withIndex()) { |  |  |  |                     for ((charIndex, textChar) in textLine.textChars.withIndex()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         if (x > textChar.start && x < textChar.end) { |  |  |  |                         if (x > textChar.start && x < textChar.end) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                             Log.e("char", "$relativePos  $lineIndex $charIndex") |  |  |  |                             Log.e("char", "$relativePos  $lineIndex $charIndex") | 
			
		
	
		
		
			
				
					
					|  |  |  |                             if (selectEnd[0] != relativePos || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { |  |  |  |                             if (selectEnd[0] != relativePos | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                                 if (selectToInt(relativePos, lineIndex, charIndex) < selectToInt( |  |  |  |                                 || selectEnd[1] != lineIndex | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                                         selectStart |  |  |  |                                 || selectEnd[2] != charIndex | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                                     ) |  |  |  |                             ) { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                 if (selectToInt(relativePos, lineIndex, charIndex) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                     < selectToInt(selectStart) | 
			
		
	
		
		
			
				
					
					|  |  |  |                                 ) { |  |  |  |                                 ) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                                     return |  |  |  |                                     return | 
			
		
	
		
		
			
				
					
					|  |  |  |                                 } |  |  |  |                                 } | 
			
		
	
	
		
		
			
				
					|  |  | @ -476,6 +480,17 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
		
			
				
					
					|  |  |  |             return stringBuilder.toString() |  |  |  |             return stringBuilder.toString() | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     val selectStartPos: Int | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         get() { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             for (i in 0 until selectStart[0]) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             return 0 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private fun selectToInt(page: Int, line: Int, char: Int): Int { |  |  |  |     private fun selectToInt(page: Int, line: Int, char: Int): Int { | 
			
		
	
		
		
			
				
					
					|  |  |  |         return page * 10000000 + line * 100000 + char |  |  |  |         return page * 10000000 + line * 100000 + char | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
	
		
		
			
				
					|  |  | @ -488,15 +503,15 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
		
			
				
					
					|  |  |  |         return when (relativePos) { |  |  |  |         return when (relativePos) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             0 -> pageOffset.toFloat() |  |  |  |             0 -> pageOffset.toFloat() | 
			
		
	
		
		
			
				
					
					|  |  |  |             1 -> pageOffset + textPage.height |  |  |  |             1 -> pageOffset + textPage.height | 
			
		
	
		
		
			
				
					
					|  |  |  |             else -> pageOffset + textPage.height + pageFactory.nextData.textPage.height |  |  |  |             else -> pageOffset + textPage.height + pageFactory.nextPage.height | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private fun relativePage(relativePos: Int): TextPage { |  |  |  |     private fun relativePage(relativePos: Int): TextPage { | 
			
		
	
		
		
			
				
					
					|  |  |  |         return when (relativePos) { |  |  |  |         return when (relativePos) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             0 -> textPage |  |  |  |             0 -> textPage | 
			
		
	
		
		
			
				
					
					|  |  |  |             1 -> pageFactory.nextData.textPage |  |  |  |             1 -> pageFactory.nextPage | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             else -> pageFactory.nextPlusData.textPage |  |  |  |             else -> pageFactory.nextPlusPage | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | 
 |