// SPDX-License-Identifier: GPL-3.0-only // Implementation of RealityReporterPanel (reality_reporter.hpp): hyphenation rules from the executable, justified line drawing and scrolling of the report area. #include "formats/executable_layout.hpp" #include "ui/reality_reporter.hpp" #include #include "ui/setup.hpp" namespace bmh::ui { namespace { constexpr int kX=66,kOrigin=46,kWidth=189,kStep=7; char folded(char c){return c>='A'&&c<='Z'?char(c+32):c;} // StartsFolded, ASCII only bool starts_folded(std::string_view word,std::string_view pattern) { if(word.size()1&&std::any_of(part.begin(),part.end(),vowel);}; if(!has_vowel(word.substr(0,split+1))||!has_vowel(word.substr(split+1,end-split)))return false; if(split&&vowel(word[split+1]))return false; // Int8's forward scan has no side effects and its count is overwritten // by each cluster length. The backward cluster/vowel walk decides the split. for(int i=int(split);i>=0;--i) { if(vowel(word[size_t(i)]))return true; for(const auto& cluster:clusters_) if(int(split)+1=0;--split) { if(!split_allowed(word,size_t(split),size_t(end)))continue; if(pending_width+font_.text_width(std::string_view(word).substr(0,size_t(split+1)))image.width||top<0||baseline>image.height)return; // DrawnFirstBy bounds if(!gradient){font_.draw(image,kX,top,text,0x5f);return;} int ramp=0;while(ramp<32&&exe_.u8(::bmh::layout::Advertising_Text_RuntimeField2Unsigned+uint32_t(ramp))!=0x5f)++ramp; if(ramp==32)throw FormatError("Reality reporter: missing Source color ramp"); Image mask(std::max(1,width),font_.height);font_.draw(mask,0,0,text,1); for(int y=0;y93) { // FormatError2: same surface, src(x66,y47), dst(x66,y40), 189x50. // Upward traversal preserves overlap and also copies the blank bottom. for(int y=0;y<96-kOrigin;++y)for(int x=0;x RealityReporterPanel::append(Image& image,RealityReporterLayoutState& state, const std::vector& messages,bool gradient) const { if(image.width!=320||image.height!=240||state.next_baseline88|| (state.next_baseline-kOrigin)%kStep||state.pending.size()>=127||state.word_ends.size()>127) throw FormatError("Reality reporter: invalid owned Source layout state"); std::vector painted; if(messages.empty())return painted; // InitializeRealityReporter does not flush silent actions for(const auto& message:messages) { size_t at=0; while(at=52)throw FormatError("Reality reporter: word exceeds Source52-byte buffer"); std::string candidate=state.pending+(state.pending.empty()?"":" ")+word; while(font_.text_width(candidate)>kWidth) { const int split=hyphenate(word,font_.text_width(state.pending)+font_.glyph(0).advance); const bool hyphen=split>=0; if(hyphen) { if(!state.pending.empty()){state.pending+=' ';state.word_ends.push_back(int(state.pending.size()-1));} state.pending+=word.substr(0,size_t(split+1));state.pending+='-'; word.erase(0,size_t(split+1)); } else if(state.pending.empty()) { // The DOS routine loops indefinitely on an unsplittable oversized // word; surface the unsupported input, do not fabricate a split. throw FormatError("Reality reporter: unsplittable oversized Source word"); } if(!state.word_ends.empty())state.word_ends.pop_back(); size_t gap=0; while(!state.word_ends.empty()&&font_.text_width(state.pending)int(state.pending.size()))throw FormatError("Reality reporter: invalid Source word boundary"); state.pending.insert(size_t(position),1,' '); for(size_t i=gap+1;i=state.word_ends.size())gap=0; } RealityReporterLine line{state.next_baseline,state.pending,true,hyphen,false}; if(font_.text_width(state.pending)<=kWidth+1)draw(image,state.pending,state.next_baseline,gradient); next_line(image,state,line);painted.push_back(std::move(line)); state.pending.clear();state.word_ends.clear();candidate=word; } if(!state.pending.empty())state.pending+=' '; state.pending+=word;state.word_ends.push_back(int(state.pending.size())); if(at