mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-10-31 01:56:52 +00:00 
			
		
		
		
	Merge remote-tracking branch 'jordan-ayers/bugfix/1049'
This commit is contained in:
		
						commit
						c4dd10fe49
					
				
					 1 changed files with 74 additions and 14 deletions
				
			
		|  | @ -195,8 +195,20 @@ struct TypesetBookImpl : TypesetBook | ||||||
| 
 | 
 | ||||||
| struct TypesetBookImpl::Typesetter : BookTypesetter | struct TypesetBookImpl::Typesetter : BookTypesetter | ||||||
| { | { | ||||||
|  |     struct PartialText { | ||||||
|  |         StyleImpl *mStyle; | ||||||
|  |         Utf8Stream::Point mBegin; | ||||||
|  |         Utf8Stream::Point mEnd; | ||||||
|  |         int mWidth; | ||||||
|  | 
 | ||||||
|  |         PartialText( StyleImpl *style, Utf8Stream::Point begin, Utf8Stream::Point end, int width) : | ||||||
|  |             mStyle(style), mBegin(begin), mEnd(end), mWidth(width) | ||||||
|  |         {} | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|     typedef TypesetBookImpl Book; |     typedef TypesetBookImpl Book; | ||||||
|     typedef boost::shared_ptr <Book> BookPtr; |     typedef boost::shared_ptr <Book> BookPtr; | ||||||
|  |     typedef std::vector<PartialText>::const_iterator PartialTextConstIterator; | ||||||
| 
 | 
 | ||||||
|     int mPageWidth; |     int mPageWidth; | ||||||
|     int mPageHeight; |     int mPageHeight; | ||||||
|  | @ -207,6 +219,8 @@ struct TypesetBookImpl::Typesetter : BookTypesetter | ||||||
|     Run * mRun; |     Run * mRun; | ||||||
| 
 | 
 | ||||||
|     std::vector <Alignment> mSectionAlignment; |     std::vector <Alignment> mSectionAlignment; | ||||||
|  |     std::vector <PartialText> mPartialWhitespace; | ||||||
|  |     std::vector <PartialText> mPartialWord; | ||||||
| 
 | 
 | ||||||
|     Book::Content const * mCurrentContent; |     Book::Content const * mCurrentContent; | ||||||
|     Alignment mCurrentAlignment; |     Alignment mCurrentAlignment; | ||||||
|  | @ -273,6 +287,8 @@ struct TypesetBookImpl::Typesetter : BookTypesetter | ||||||
| 
 | 
 | ||||||
|     intptr_t addContent (Utf8Span text, bool select) |     intptr_t addContent (Utf8Span text, bool select) | ||||||
|     { |     { | ||||||
|  |         add_partial_text(); | ||||||
|  | 
 | ||||||
|         Contents::iterator i = mBook->mContents.insert (mBook->mContents.end (), Content (text.first, text.second)); |         Contents::iterator i = mBook->mContents.insert (mBook->mContents.end (), Content (text.first, text.second)); | ||||||
| 
 | 
 | ||||||
|         if (select) |         if (select) | ||||||
|  | @ -283,6 +299,8 @@ struct TypesetBookImpl::Typesetter : BookTypesetter | ||||||
| 
 | 
 | ||||||
|     void selectContent (intptr_t contentHandle) |     void selectContent (intptr_t contentHandle) | ||||||
|     { |     { | ||||||
|  |         add_partial_text(); | ||||||
|  | 
 | ||||||
|         mCurrentContent = reinterpret_cast <Content const *> (contentHandle); |         mCurrentContent = reinterpret_cast <Content const *> (contentHandle); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -302,12 +320,16 @@ struct TypesetBookImpl::Typesetter : BookTypesetter | ||||||
|     { |     { | ||||||
|         assert (margin == 0); //TODO: figure out proper behavior here...
 |         assert (margin == 0); //TODO: figure out proper behavior here...
 | ||||||
| 
 | 
 | ||||||
|  |         add_partial_text(); | ||||||
|  | 
 | ||||||
|         mRun = NULL; |         mRun = NULL; | ||||||
|         mLine = NULL; |         mLine = NULL; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     void sectionBreak (float margin) |     void sectionBreak (float margin) | ||||||
|     { |     { | ||||||
|  |         add_partial_text(); | ||||||
|  | 
 | ||||||
|         if (mBook->mSections.size () > 0) |         if (mBook->mSections.size () > 0) | ||||||
|         { |         { | ||||||
|             mRun = NULL; |             mRun = NULL; | ||||||
|  | @ -321,6 +343,8 @@ struct TypesetBookImpl::Typesetter : BookTypesetter | ||||||
| 
 | 
 | ||||||
|     void setSectionAlignment (Alignment sectionAlignment) |     void setSectionAlignment (Alignment sectionAlignment) | ||||||
|     { |     { | ||||||
|  |         add_partial_text(); | ||||||
|  | 
 | ||||||
|         if (mSection != NULL) |         if (mSection != NULL) | ||||||
|             mSectionAlignment.back () = sectionAlignment; |             mSectionAlignment.back () = sectionAlignment; | ||||||
|         mCurrentAlignment = sectionAlignment; |         mCurrentAlignment = sectionAlignment; | ||||||
|  | @ -331,6 +355,8 @@ struct TypesetBookImpl::Typesetter : BookTypesetter | ||||||
|         int curPageStart = 0; |         int curPageStart = 0; | ||||||
|         int curPageStop  = 0; |         int curPageStop  = 0; | ||||||
| 
 | 
 | ||||||
|  |         add_partial_text(); | ||||||
|  | 
 | ||||||
|         std::vector <Alignment>::iterator sa = mSectionAlignment.begin (); |         std::vector <Alignment>::iterator sa = mSectionAlignment.begin (); | ||||||
|         for (Sections::iterator i = mBook->mSections.begin (); i != mBook->mSections.end (); ++i, ++sa) |         for (Sections::iterator i = mBook->mSections.begin (); i != mBook->mSections.end (); ++i, ++sa) | ||||||
|         { |         { | ||||||
|  | @ -415,23 +441,23 @@ struct TypesetBookImpl::Typesetter : BookTypesetter | ||||||
| 
 | 
 | ||||||
|     void writeImpl (StyleImpl * style, Utf8Stream::Point _begin, Utf8Stream::Point _end) |     void writeImpl (StyleImpl * style, Utf8Stream::Point _begin, Utf8Stream::Point _end) | ||||||
|     { |     { | ||||||
|         int line_height = style->mFont->getDefaultHeight (); |  | ||||||
| 
 |  | ||||||
|         Utf8Stream stream (_begin, _end); |         Utf8Stream stream (_begin, _end); | ||||||
| 
 | 
 | ||||||
|         while (!stream.eof ()) |         while (!stream.eof ()) | ||||||
|         { |         { | ||||||
|             if (ucsLineBreak (stream.peek ())) |             if (ucsLineBreak (stream.peek ())) | ||||||
|             { |             { | ||||||
|  |                 add_partial_text(); | ||||||
|                 stream.consume (); |                 stream.consume (); | ||||||
|                 mLine = NULL, mRun = NULL; |                 mLine = NULL, mRun = NULL; | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  |             if (ucsBreakingSpace (stream.peek ()) && !mPartialWord.empty()) | ||||||
|  |                 add_partial_text(); | ||||||
|  | 
 | ||||||
|             int word_width = 0; |             int word_width = 0; | ||||||
|             int word_height = 0; |  | ||||||
|             int space_width = 0; |             int space_width = 0; | ||||||
|             int character_count = 0; |  | ||||||
| 
 | 
 | ||||||
|             Utf8Stream::Point lead = stream.current (); |             Utf8Stream::Point lead = stream.current (); | ||||||
| 
 | 
 | ||||||
|  | @ -450,8 +476,6 @@ struct TypesetBookImpl::Typesetter : BookTypesetter | ||||||
|                 MyGUI::GlyphInfo* gi = style->mFont->getGlyphInfo (stream.peek ()); |                 MyGUI::GlyphInfo* gi = style->mFont->getGlyphInfo (stream.peek ()); | ||||||
|                 if (gi) |                 if (gi) | ||||||
|                     word_width += gi->advance + gi->bearingX; |                     word_width += gi->advance + gi->bearingX; | ||||||
|                 word_height = line_height; |  | ||||||
|                 ++character_count; |  | ||||||
|                 stream.consume (); |                 stream.consume (); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  | @ -460,21 +484,57 @@ struct TypesetBookImpl::Typesetter : BookTypesetter | ||||||
|             if (lead == extent) |             if (lead == extent) | ||||||
|                 break; |                 break; | ||||||
| 
 | 
 | ||||||
|             int left = mLine ? mLine->mRect.right : 0; |             if ( lead != origin ) | ||||||
|  |                 mPartialWhitespace.push_back (PartialText (style, lead, origin, space_width)); | ||||||
|  |             if ( origin != extent ) | ||||||
|  |                 mPartialWord.push_back (PartialText (style, origin, extent, word_width)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|             if (left + space_width + word_width > mPageWidth) |     void add_partial_text () | ||||||
|             { |     { | ||||||
|                 mLine = NULL, mRun = NULL; |         if (mPartialWhitespace.empty() && mPartialWord.empty()) | ||||||
|  |             return; | ||||||
| 
 | 
 | ||||||
|                 append_run (style, origin, extent, extent - origin, word_width, mBook->mRect.bottom + word_height); |         int space_width = 0; | ||||||
|             } |         int word_width  = 0; | ||||||
|             else | 
 | ||||||
|  |         for (PartialTextConstIterator i = mPartialWhitespace.begin (); i != mPartialWhitespace.end (); ++i) | ||||||
|  |             space_width += i->mWidth; | ||||||
|  |         for (PartialTextConstIterator i = mPartialWord.begin (); i != mPartialWord.end (); ++i) | ||||||
|  |             word_width += i->mWidth; | ||||||
|  | 
 | ||||||
|  |         int left = mLine ? mLine->mRect.right : 0; | ||||||
|  | 
 | ||||||
|  |         if (left + space_width + word_width > mPageWidth) | ||||||
|  |         { | ||||||
|  |             mLine = NULL, mRun = NULL, left = 0; | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|  |             for (PartialTextConstIterator i = mPartialWhitespace.begin (); i != mPartialWhitespace.end (); ++i) | ||||||
|             { |             { | ||||||
|                 int top = mLine ? mLine->mRect.top : mBook->mRect.bottom; |                 int top = mLine ? mLine->mRect.top : mBook->mRect.bottom; | ||||||
|  |                 int line_height = i->mStyle->mFont->getDefaultHeight (); | ||||||
| 
 | 
 | ||||||
|                 append_run (style, lead, extent, extent - origin, left + space_width + word_width, top + word_height); |                 append_run ( i->mStyle, i->mBegin, i->mEnd, 0, left + i->mWidth, top + line_height); | ||||||
|  | 
 | ||||||
|  |                 left = mLine->mRect.right; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         for (PartialTextConstIterator i = mPartialWord.begin (); i != mPartialWord.end (); ++i) | ||||||
|  |         { | ||||||
|  |             int top = mLine ? mLine->mRect.top : mBook->mRect.bottom; | ||||||
|  |             int line_height = i->mStyle->mFont->getDefaultHeight (); | ||||||
|  | 
 | ||||||
|  |             append_run (i->mStyle, i->mBegin, i->mEnd, i->mEnd - i->mBegin, left + i->mWidth, top + line_height); | ||||||
|  | 
 | ||||||
|  |             left = mLine->mRect.right; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         mPartialWhitespace.clear(); | ||||||
|  |         mPartialWord.clear(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void append_run (StyleImpl * style, Utf8Stream::Point begin, Utf8Stream::Point end, int pc, int right, int bottom) |     void append_run (StyleImpl * style, Utf8Stream::Point begin, Utf8Stream::Point end, int pc, int right, int bottom) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue