[Git][wxwidgets/wxwidgets][master] Make GTK3 dashed line appearance similar to MSW

1 view
Skip to first unread message

Vadim Zeitlin (@_VZ_)

unread,
May 13, 2026, 2:55:31 AM (4 days ago) May 13
to wx-commi...@googlegroups.com

Vadim Zeitlin pushed to branch master at wxWidgets / wxWidgets

Commits:

  • ec0149a9
    by Paul Cornett at 2026-05-12T23:31:39-07:00
    Make GTK3 dashed line appearance similar to MSW
    
    Scale the segment lengths to the pen width properly, and match the MSW lengths.
    Apparently MSW doesn't have a long dash, so use twice the short dash for that.
    See #26449
    

1 changed file:

Changes:

  • src/generic/graphicc.cpp
    ... ... @@ -306,8 +306,7 @@ private :
    306 306
         cairo_line_join_t m_join;
    
    307 307
     
    
    308 308
         int m_count;
    
    309
    -    const double *m_lengths;
    
    310
    -    double *m_userLengths;
    
    309
    +    double* m_lengths;
    
    311 310
     
    
    312 311
         wxDECLARE_NO_COPY_CLASS(wxCairoPenData);
    
    313 312
     };
    
    ... ... @@ -846,14 +845,13 @@ wxCairoPenBrushBaseData::CreateRadialGradientPattern(wxDouble startX, wxDouble s
    846 845
     
    
    847 846
     wxCairoPenData::~wxCairoPenData()
    
    848 847
     {
    
    849
    -    delete[] m_userLengths;
    
    848
    +    delete[] m_lengths;
    
    850 849
     }
    
    851 850
     
    
    852 851
     void wxCairoPenData::Init()
    
    853 852
     {
    
    854 853
         m_pattern = nullptr;
    
    855 854
         m_lengths = nullptr;
    
    856
    -    m_userLengths = nullptr;
    
    857 855
         m_width = 0;
    
    858 856
         m_count = 0;
    
    859 857
     }
    
    ... ... @@ -902,24 +900,6 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPe
    902 900
             break;
    
    903 901
         }
    
    904 902
     
    
    905
    -    const double dashUnit = m_width < 1.0 ? 1.0 : m_width;
    
    906
    -    const double dotted[] =
    
    907
    -    {
    
    908
    -        dashUnit , dashUnit + 2.0
    
    909
    -    };
    
    910
    -    static const double short_dashed[] =
    
    911
    -    {
    
    912
    -        9.0 , 6.0
    
    913
    -    };
    
    914
    -    static const double dashed[] =
    
    915
    -    {
    
    916
    -        19.0 , 9.0
    
    917
    -    };
    
    918
    -    static const double dotted_dashed[] =
    
    919
    -    {
    
    920
    -        9.0 , 6.0 , 3.0 , 3.0
    
    921
    -    };
    
    922
    -
    
    923 903
         switch ( info.GetStyle() )
    
    924 904
         {
    
    925 905
         case wxPENSTYLE_SOLID :
    
    ... ... @@ -945,25 +925,33 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPe
    945 925
             break;
    
    946 926
     
    
    947 927
         case wxPENSTYLE_DOT :
    
    948
    -        m_count = WXSIZEOF(dotted);
    
    949
    -        m_userLengths = new double[ m_count ] ;
    
    950
    -        memcpy( m_userLengths, dotted, sizeof(dotted) );
    
    951
    -        m_lengths = m_userLengths;
    
    928
    +        m_count = 2;
    
    929
    +        m_lengths = new double[m_count];
    
    930
    +        m_lengths[0] = 1;
    
    931
    +        m_lengths[1] = 1;
    
    952 932
             break;
    
    953 933
     
    
    954 934
         case wxPENSTYLE_LONG_DASH :
    
    955
    -        m_lengths = dashed ;
    
    956
    -        m_count = WXSIZEOF(dashed);
    
    935
    +        m_count = 2;
    
    936
    +        m_lengths = new double[m_count];
    
    937
    +        m_lengths[0] = 6;
    
    938
    +        m_lengths[1] = 1;
    
    957 939
             break;
    
    958 940
     
    
    959 941
         case wxPENSTYLE_SHORT_DASH :
    
    960
    -        m_lengths = short_dashed ;
    
    961
    -        m_count = WXSIZEOF(short_dashed);
    
    942
    +        m_count = 2;
    
    943
    +        m_lengths = new double[m_count];
    
    944
    +        m_lengths[0] = 3;
    
    945
    +        m_lengths[1] = 1;
    
    962 946
             break;
    
    963 947
     
    
    964 948
         case wxPENSTYLE_DOT_DASH :
    
    965
    -        m_lengths = dotted_dashed ;
    
    966
    -        m_count = WXSIZEOF(dotted_dashed);
    
    949
    +        m_count = 4;
    
    950
    +        m_lengths = new double[m_count];
    
    951
    +        m_lengths[0] = 1;
    
    952
    +        m_lengths[1] = 1;
    
    953
    +        m_lengths[2] = 3;
    
    954
    +        m_lengths[3] = 1;
    
    967 955
             break;
    
    968 956
     
    
    969 957
         case wxPENSTYLE_USER_DASH :
    
    ... ... @@ -972,18 +960,12 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPe
    972 960
                 m_count = info.GetDashes( &wxdashes ) ;
    
    973 961
                 if ((wxdashes != nullptr) && (m_count > 0))
    
    974 962
                 {
    
    975
    -                m_userLengths = new double[m_count] ;
    
    963
    +                m_lengths = new double[m_count];
    
    976 964
                     for ( int i = 0 ; i < m_count ; ++i )
    
    977 965
                     {
    
    978
    -                    m_userLengths[i] = wxdashes[i] * dashUnit ;
    
    979
    -
    
    980
    -                    if ( i % 2 == 1 && m_userLengths[i] < dashUnit + 2.0 )
    
    981
    -                        m_userLengths[i] = dashUnit + 2.0 ;
    
    982
    -                    else if ( i % 2 == 0 && m_userLengths[i] < dashUnit )
    
    983
    -                        m_userLengths[i] = dashUnit ;
    
    966
    +                    m_lengths[i] = wxdashes[i];
    
    984 967
                     }
    
    985 968
                 }
    
    986
    -            m_lengths = m_userLengths ;
    
    987 969
             }
    
    988 970
             break;
    
    989 971
     
    
    ... ... @@ -1007,6 +989,19 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPe
    1007 989
             break;
    
    1008 990
         }
    
    1009 991
     
    
    992
    +    const double dashUnit = wxMax(m_width, 1.0);
    
    993
    +    for (int i = 0; i < m_count; i++)
    
    994
    +    {
    
    995
    +        if (m_cap != CAIRO_LINE_CAP_BUTT)
    
    996
    +        {
    
    997
    +            // Rounded/projecting cap will extend 0.5 on either side of "on" segment,
    
    998
    +            // increase "off" length, decrease "on" to account for this.
    
    999
    +            // Note that 0-length "on" is valid.
    
    1000
    +            m_lengths[i] += (i & 1) ? 1 : -1;
    
    1001
    +        }
    
    1002
    +        m_lengths[i] *= dashUnit;
    
    1003
    +    }
    
    1004
    +
    
    1010 1005
         switch ( info.GetGradientType() )
    
    1011 1006
         {
    
    1012 1007
         case wxGRADIENT_NONE:
    
    ... ... @@ -1048,7 +1043,11 @@ void wxCairoPenData::Apply( wxGraphicsContext* context )
    1048 1043
         cairo_set_line_width(ctext, width);
    
    1049 1044
         cairo_set_line_cap(ctext,m_cap);
    
    1050 1045
         cairo_set_line_join(ctext,m_join);
    
    1051
    -    cairo_set_dash(ctext, m_lengths, m_count, 0);
    
    1046
    +
    
    1047
    +    double dashOffset = 0;
    
    1048
    +    if (m_count && m_cap == CAIRO_LINE_CAP_BUTT && context->ShouldOffset())
    
    1049
    +        dashOffset = 0.5;
    
    1050
    +    cairo_set_dash(ctext, m_lengths, m_count, dashOffset);
    
    1052 1051
     }
    
    1053 1052
     
    
    1054 1053
     //-----------------------------------------------------------------------------
    


View it on GitLab.
You're receiving this email because of your account on gitlab.com. Manage all notifications · Help Notification message regarding https://gitlab.com/wxwidgets/wxwidgets/-/commit/ec0149a9320549efd41e02c24a1b744b217d04f1 at 1778655326

Reply all
Reply to author
Forward
0 new messages