Skip to content

Sizes are wrong when use_swt_fonts value is true #40

@lonelion

Description

@lonelion
Image

Description

When the use_swt_fonts flag is enabled, the computed sizes (computeSize) of some widgets (e.g., Button and Link) are incorrect.

The use_swt_fonts flag determines whether the widget uses:

  • The font and foreground color provided by Java (SWT), or
  • The font rendered by Flutter

In the reported case (use_swt_fonts = true), the size calculation does not match the expected values.

Technical Context

Sizes are calculated in Sizes.java.

For Button and Link, the computeSize() method is auto-generated.

The generation flow is the following:

  1. Classes to be generated are added in measure.dart.
  2. The GenerateAll task is executed. This generates:
    • WidgetSizeTest.java
    • measure_widget.dart
    • Other supporting files.
  3. The following command is executed:

flutter run -d windows -t tool/measure_widget.dart

NOTE: (Replace windows with the corresponding OS.)

This generates the constants used to approximate computeSize(). Although the measurement is performed using Flutter code, additional heuristics are applied to estimate the final size.

  1. Finally, widgetSizes.java is generated.

Validation

WidgetSizeTest.java contains the tests that validate whether widgetSizes.java was generated correctly.

These tests:

  • Measure the widget in Java
  • Measure the widget in Flutter
  • Compare both results across different scenarios

Covered scenarios include:

  • Minimum size (widget occupies the smallest possible space)
  • Respecting bounds
  • Bold/italic font cases
  • flutter_should_equal_java comparison cases

All these tests must pass, as they ensure widgetSizes.java is correctly aligned with both Java and Flutter measurements.

Expected Behavior

  • When use_swt_fonts = true, computeSize() should:
  • Correctly reflect Java (SWT) font metrics.
  • Pass all WidgetSizeTest tests.
  • Maintain consistency between Java and Flutter measurements in the flutter_should_equal_java scenarios.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions