mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-25 11:26:37 +00:00 
			
		
		
		
	Fix line breaks around IMG tags.
This commit is contained in:
		
							parent
							
								
									c5e85ebddc
								
							
						
					
					
						commit
						3287d0b6ef
					
				
					 1 changed files with 14 additions and 15 deletions
				
			
		|  | @ -81,7 +81,6 @@ namespace MWGui | ||||||
| 
 | 
 | ||||||
|                         if (type == Event_ImgTag) |                         if (type == Event_ImgTag) | ||||||
|                         { |                         { | ||||||
|                             mIgnoreLineEndings = false; |  | ||||||
|                             mIgnoreNewlineTags = false; |                             mIgnoreNewlineTags = false; | ||||||
|                         } |                         } | ||||||
| 
 | 
 | ||||||
|  | @ -200,6 +199,7 @@ namespace MWGui | ||||||
|             BookTextParser parser(markup); |             BookTextParser parser(markup); | ||||||
| 
 | 
 | ||||||
|             bool brBeforeLastTag = false; |             bool brBeforeLastTag = false; | ||||||
|  |             bool isPrevImg = false; | ||||||
|             for (;;) |             for (;;) | ||||||
|             { |             { | ||||||
|                 BookTextParser::Events event = parser.next(); |                 BookTextParser::Events event = parser.next(); | ||||||
|  | @ -212,22 +212,17 @@ namespace MWGui | ||||||
|                 else |                 else | ||||||
|                 { |                 { | ||||||
|                     // Each block of text (between two tags / boundary and tag) will be displayed in a separate editbox widget,
 |                     // Each block of text (between two tags / boundary and tag) will be displayed in a separate editbox widget,
 | ||||||
|                     // which means an additonal linebreak will be created.
 |                     // which means an additonal linebreak will be created between them.
 | ||||||
|                     // ^ This is not the case in vanilla MW (though having multiple tags in one line seems to result in undefined behavior).
 |                     // ^ This is not what vanilla MW assumes, so we must deal with line breaks around tags appropriately.
 | ||||||
|                     // We must deal with linebreaks around tags appropriately.
 |  | ||||||
|                     { |  | ||||||
|                     bool brAtStart = (plainText[0] == '\n'); |                     bool brAtStart = (plainText[0] == '\n'); | ||||||
|                     bool brAtEnd = (plainText[plainText.size()-1] == '\n'); |                     bool brAtEnd = (plainText[plainText.size()-1] == '\n'); | ||||||
| 
 | 
 | ||||||
|                         if (!brBeforeLastTag && brAtStart) |                     if (brAtStart && !brBeforeLastTag && !isPrevImg) | ||||||
|                         plainText.erase(plainText.begin()); |                         plainText.erase(plainText.begin()); | ||||||
| 
 | 
 | ||||||
|                     if (plainText.size() && brAtEnd) |                     if (plainText.size() && brAtEnd) | ||||||
|                         plainText.erase(plainText.end()-1); |                         plainText.erase(plainText.end()-1); | ||||||
| 
 | 
 | ||||||
|                         brBeforeLastTag = brAtEnd; |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
| #if (MYGUI_VERSION < MYGUI_DEFINE_VERSION(3, 2, 2)) | #if (MYGUI_VERSION < MYGUI_DEFINE_VERSION(3, 2, 2)) | ||||||
|                     // splitting won't be fully functional until 3.2.2 (see TextElement::pageSplit())
 |                     // splitting won't be fully functional until 3.2.2 (see TextElement::pageSplit())
 | ||||||
|                     // hack: prevent newlines at the end of the book possibly creating unnecessary pages
 |                     // hack: prevent newlines at the end of the book possibly creating unnecessary pages
 | ||||||
|  | @ -238,16 +233,20 @@ namespace MWGui | ||||||
|                     } |                     } | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|                     if (!plainText.empty()) |                     if (!plainText.empty() || brBeforeLastTag || isPrevImg) | ||||||
|                     { |                     { | ||||||
|                         TextElement elem(paper, pag, mTextStyle, plainText); |                         TextElement elem(paper, pag, mTextStyle, plainText); | ||||||
|                         elem.paginate(); |                         elem.paginate(); | ||||||
|                     } |                     } | ||||||
|  | 
 | ||||||
|  |                     brBeforeLastTag = brAtEnd; | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 if (event == BookTextParser::Event_EOF) |                 if (event == BookTextParser::Event_EOF) | ||||||
|                     break; |                     break; | ||||||
| 
 | 
 | ||||||
|  |                 isPrevImg = (event == BookTextParser::Event_ImgTag); | ||||||
|  | 
 | ||||||
|                 switch (event) |                 switch (event) | ||||||
|                 { |                 { | ||||||
|                     case BookTextParser::Event_ImgTag: |                     case BookTextParser::Event_ImgTag: | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue