mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:22:43 +00:00 
			
		
		
		
	 9121cc7cae
			
		
	
	
		9121cc7cae
		
	
	
	
	
		
			
			This requires an implementation of the "text preparation algorithm" as specified here: html.spec.whatwg.org/multipage/canvas.html#text-preparation-algorithm However, we're missing a lot of things such as the CanvasTextDrawingStyles interface, so most of the algorithm was not implemented. Additionally, we also are not able to use a LineBox like the algorithm suggests, because our layouting infra is not up to the task yet. The prepare_text function does nothing other than figuring out the width of the given text and return glyphs with offsets at the moment.
		
			
				
	
	
		
			66 lines
		
	
	
	
		
			2.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
	
		
			2.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <LibJS/Heap/Handle.h>
 | |
| #include <LibWeb/Bindings/Wrappable.h>
 | |
| 
 | |
| namespace Web::HTML {
 | |
| 
 | |
| class TextMetrics
 | |
|     : public RefCounted<TextMetrics>
 | |
|     , public Bindings::Wrappable {
 | |
| public:
 | |
|     using WrapperType = Bindings::TextMetricsWrapper;
 | |
| 
 | |
|     static RefPtr<TextMetrics> create();
 | |
| 
 | |
|     double width() const { return m_width; }
 | |
|     double actual_bounding_box_left() const { return m_actual_bounding_box_left; }
 | |
|     double actual_bounding_box_right() const { return m_actual_bounding_box_right; }
 | |
|     double font_bounding_box_ascent() const { return m_font_bounding_box_ascent; }
 | |
|     double font_bounding_box_descent() const { return m_font_bounding_box_descent; }
 | |
|     double actual_bounding_box_ascent() const { return m_actual_bounding_box_ascent; }
 | |
|     double actual_bounding_box_descent() const { return m_actual_bounding_box_descent; }
 | |
|     double em_height_ascent() const { return m_em_height_ascent; }
 | |
|     double em_height_descent() const { return m_em_height_descent; }
 | |
|     double hanging_baseline() const { return m_hanging_baseline; }
 | |
|     double alphabetic_baseline() const { return m_alphabetic_baseline; }
 | |
|     double ideographic_baseline() const { return m_ideographic_baseline; }
 | |
| 
 | |
|     void set_width(double width) { m_width = width; }
 | |
|     void set_actual_bounding_box_left(double left) { m_actual_bounding_box_left = left; }
 | |
|     void set_actual_bounding_box_right(double right) { m_actual_bounding_box_right = right; }
 | |
|     void set_font_bounding_box_ascent(double ascent) { m_font_bounding_box_ascent = ascent; }
 | |
|     void set_font_bounding_box_descent(double descent) { m_font_bounding_box_descent = descent; }
 | |
|     void set_actual_bounding_box_ascent(double ascent) { m_actual_bounding_box_ascent = ascent; }
 | |
|     void set_actual_bounding_box_descent(double descent) { m_actual_bounding_box_descent = descent; }
 | |
|     void set_em_height_ascent(double ascent) { m_em_height_ascent = ascent; }
 | |
|     void set_em_height_descent(double descent) { m_em_height_descent = descent; }
 | |
|     void set_hanging_baseline(double baseline) { m_hanging_baseline = baseline; }
 | |
|     void set_alphabetic_baseline(double baseline) { m_alphabetic_baseline = baseline; }
 | |
|     void set_ideographic_baseline(double baseline) { m_ideographic_baseline = baseline; }
 | |
| 
 | |
| private:
 | |
|     explicit TextMetrics() { }
 | |
| 
 | |
|     double m_width { 0 };
 | |
|     double m_actual_bounding_box_left { 0 };
 | |
|     double m_actual_bounding_box_right { 0 };
 | |
| 
 | |
|     double m_font_bounding_box_ascent { 0 };
 | |
|     double m_font_bounding_box_descent { 0 };
 | |
|     double m_actual_bounding_box_ascent { 0 };
 | |
|     double m_actual_bounding_box_descent { 0 };
 | |
|     double m_em_height_ascent { 0 };
 | |
|     double m_em_height_descent { 0 };
 | |
|     double m_hanging_baseline { 0 };
 | |
|     double m_alphabetic_baseline { 0 };
 | |
|     double m_ideographic_baseline { 0 };
 | |
| };
 | |
| 
 | |
| }
 |