22 return Point(size.width, size.height);
25using VS = GlyphAtlasPipeline::VertexShader;
26using FS = GlyphAtlasPipeline::FragmentShader;
45 inherited_opacity_ = opacity;
57 force_text_color_ =
value;
61 const Matrix entity_offset_transform =
63 return frame_->GetBounds().TransformBounds(entity_offset_transform);
68 const std::optional<StrokeParameters>& stroke) {
69 if (frame_->HasColor()) {
76 properties_.
stroke = stroke;
83 const Scalar epsilon = 0.005f;
84 if (std::abs(
x - 1.f) < epsilon) {
87 if (std::abs(
x + 1.f) < epsilon) {
96 const Matrix& entity_transform,
97 const std::shared_ptr<TextFrame>& frame,
99 const Matrix& screen_transform,
101 const std::shared_ptr<GlyphAtlas>& atlas) {
109 constexpr std::array<Point, 4> unit_points = {
Point{0, 0},
Point{1, 0},
112 Matrix entity_offset_transform =
115 ISize atlas_size = atlas->GetTexture()->GetSize();
117 Matrix basis_transform = entity_offset_transform.
Basis();
119 VS::PerVertexData vtx;
122 const Matrix frame_transform =
133 unscaled_basis.
m[0] = AttractToOne(unscaled_basis.
m[0]);
134 unscaled_basis.
m[5] = AttractToOne(unscaled_basis.
m[5]);
137 Point screen_offset = (entity_offset_transform *
Point(0, 0));
139 for (
const TextRun& run : frame->GetRuns()) {
140 const Font& font = run.GetFont();
141 const ScaledFont scaled_font{.
font = font, .scale = rounded_scale};
142 const FontGlyphAtlas* font_atlas = atlas->GetFontGlyphAtlas(scaled_font);
157 Point subpixel_adjustment(0.5, 0.5);
162 subpixel_adjustment.
x = 0.125;
165 subpixel_adjustment.
y = 0.125;
168 subpixel_adjustment.
x = 0.125;
169 subpixel_adjustment.
y = 0.125;
174 run.GetGlyphPositions()) {
202 for (
const Point& point : unit_points) {
204 if (is_translation_scale) {
205 Point unrounded_glyph_position =
208 (basis_transform * glyph_position.position);
210 Point screen_glyph_position =
211 (screen_offset + unrounded_glyph_position + subpixel_adjustment)
214 (screen_glyph_position +
220 position = entity_offset_transform *
221 (glyph_position.position + scaled_bounds.
GetLeftTop() +
222 point * scaled_bounds.
GetSize());
224 vtx.uv = uv_origin + (uv_size * point);
225 vtx.position = position;
226 vtx_contents[
i++] = vtx;
241 const std::shared_ptr<GlyphAtlas>& atlas =
245 if (!atlas || !atlas->IsValid()) {
257 VS::FrameInfo frame_info;
266 FS::FragInfo frag_info;
267 frag_info.use_text_color = force_text_color_ ? 1.0 : 0.0;
275 if (is_translation_scale) {
285 constexpr Scalar kMinScaleForRatio = 0.001f;
286 constexpr Scalar kAnisotropicScaleThreshold = 1.15f;
289 const Scalar ratio = (sx > sy) ? sx / std::max(sy, kMinScaleForRatio)
290 : sy / std::max(sx, kMinScaleForRatio);
291 if (ratio > kAnisotropicScaleThreshold) {
312 FS::BindGlyphAtlasSampler(
315 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
321 size_t glyph_count = 0;
322 for (
const auto& run : frame_->GetRuns()) {
323 glyph_count += run.GetGlyphPositions().size();
325 size_t vertex_count = glyph_count * 4;
326 size_t index_count = glyph_count * 6;
329 vertex_count *
sizeof(VS::PerVertexData),
alignof(VS::PerVertexData),
331 VS::PerVertexData* vtx_contents =
332 reinterpret_cast<VS::PerVertexData*
>(data);
342 index_count *
sizeof(uint16_t),
alignof(uint16_t), [&](uint8_t* data) {
343 uint16_t* indices =
reinterpret_cast<uint16_t*
>(data);
345 for (
auto i = 0u;
i < glyph_count;
i++) {
347 indices[j++] =
base + 0;
348 indices[j++] =
base + 1;
349 indices[j++] =
base + 2;
350 indices[j++] =
base + 1;
351 indices[j++] =
base + 2;
352 indices[j++] =
base + 3;
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
const std::shared_ptr< LazyGlyphAtlas > & GetLazyGlyphAtlas() const
PipelineRef GetGlyphAtlasPipeline(ContentContextOptions opts) const
HostBuffer & GetTransientsIndexesBuffer() const
Retrieve the current host buffer for transient storage of indexes used for indexed draws.
std::shared_ptr< Context > GetContext() const
Matrix GetShaderTransform(const RenderPass &pass) const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
float GetShaderClipDepth() const
An object that can look up glyph locations within the GlyphAtlas for a particular typeface.
std::optional< FrameBounds > FindGlyphBounds(const SubpixelGlyph &glyph) const
Find the location of a glyph in the atlas.
Describes a typeface along with any modifications to its intrinsic properties.
AxisAlignment GetAxisAlignment() const
Type
Describes how the glyphs are represented in the texture.
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
BufferView EmplaceUniform(const UniformType &uniform)
Emplace uniform data onto the host buffer. Ensure that backend specific uniform alignment requirement...
Render passes encode render commands directed as one specific render target into an underlying comman...
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
virtual bool SetIndexBuffer(BufferView index_buffer, IndexType index_type)
Specify an index buffer to use for this command. To unset the index buffer, pass IndexType::kNone to ...
virtual void SetPipeline(PipelineRef pipeline)
The pipeline to use for this command.
virtual fml::Status Draw()
Record the currently pending command.
virtual void SetElementCount(size_t count)
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
static void ComputeVertexData(GlyphAtlasPipeline::VertexShader::PerVertexData *vtx_contents, const Matrix &entity_transform, const std::shared_ptr< TextFrame > &frame, Point position, const Matrix &screen_transform, GlyphProperties glyph_properties, const std::shared_ptr< GlyphAtlas > &atlas)
Computes the vertex data for the render operation from a collection of data drawn from the DrawTextFr...
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
void SetForceTextColor(bool value)
Force the text color to apply to the rendered glyphs, even if those glyphs are bitmaps.
void SetTextProperties(Color color, const std::optional< StrokeParameters > &stroke)
Must be set after text frame.
void SetPosition(Point position)
void SetScreenTransform(const Matrix &transform)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
void SetTextFrame(const std::shared_ptr< TextFrame > &frame)
void SetColor(Color color)
static Rational RoundScaledFontSize(Scalar scale)
static SubpixelPosition ComputeSubpixelPosition(const TextRun::GlyphPosition &glyph_position, AxisAlignment alignment, const Matrix &transform)
Represents a collection of positioned glyphs from a specific font.
LinePipeline::FragmentShader FS
@ kBase
The texture is sampled as if it only had a single mipmap level.
Point SizeToPoint(Size size)
constexpr Vector4 ToVector(Color color)
LinePipeline::VertexShader VS
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
@ kNearest
Select nearest to the sample point. Most widely supported.
impeller::ShaderType type
constexpr bool IsTransparent() const
constexpr Color WithAlpha(Scalar new_alpha) const
constexpr Color Premultiply() const
Rect atlas_bounds
The bounds of the glyph within the glyph atlas texture.
Rect glyph_bounds
The glyph bounds within the local coordinate system.
static Tone ComputeTone(const Color &c)
ToneOrColor tone_or_color
std::optional< StrokeParameters > stroke
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeTranslation(const Vector3 &t)
constexpr Vector3 GetBasisY() const
constexpr bool IsTranslationScaleOnly() const
Returns true if the matrix has a scale-only basis and is non-projective. Note that an identity matrix...
constexpr Matrix Basis() const
The Matrix without its w components (without translation).
static constexpr Matrix MakeScale(const Vector3 &s)
constexpr Vector3 GetBasisX() const
Scalar GetMaxBasisLengthXY() const
Return the maximum scale applied specifically to either the X axis or Y axis unit vectors (the bases)...
A font and a scale. Used as a key that represents a typeface within a glyph atlas.
A glyph and its subpixel position.
static constexpr TPoint Round(const TPoint< U > &other)
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
constexpr TPoint< T > GetLeftTop() const
constexpr TRect Scale(Type scale) const