#pragma once #include "pdfengine/edit_session.hpp" #include "fonts/shaping/hb_shaper.hpp" #include "fonts/face/font_face.hpp" #include #include #include namespace pdfengine::text { struct LayoutConstraints { double columnLeft = 0.0; double columnRight = 0.0; double firstBaselineY = 0.0; double leading = 0.0; std::string align = "left"; double hangingIndent = 0.0; }; class LineBreaker { public: LineBreaker(const LayoutConstraints& constraints); // Processes a stream of shaped glyphs and applies line breaking void ProcessRun( const std::vector& shapedGlyphs, const std::string& runText, double fontSize, const fonts::FontFace& face, double scale ); // Finalizes the layout and populates the LayoutResult void Finalize(LayoutResult& outLayout); private: LayoutConstraints constraints_; double currentX_; double currentY_; // Internal state for word wrapping std::vector currentLineGlyphs_; std::vector finishedLines_; std::vector allGlyphs_; void CommitLine(); }; class TextLayoutEngine { public: TextLayoutEngine(); // Computes layout for a given text run (simplified for single font for now) LayoutResult ComputeLayout( const std::string& text, const LayoutConstraints& constraints, fonts::FontFace& fontFace, double fontSize ); private: fonts::HbShaper shaper_; }; } // namespace pdfengine::text