@@ -705,6 +705,40 @@ MeasureString (GpGraphics *graphics, GDIPCONST WCHAR *stringUnicode, int *length
705
705
boundingBox -> Width = gdip_convgr_unitx (graphics , boundingBox -> Width );
706
706
boundingBox -> Height = gdip_convgr_unity (graphics , boundingBox -> Height );
707
707
}
708
+
709
+ switch (AlignVert ) {
710
+ case StringAlignmentCenter :
711
+ if (format -> formatFlags & StringFormatFlagsDirectionVertical ) {
712
+ boundingBox -> X += (FrameHeight - MaxY ) * 0.5 ;
713
+ } else {
714
+ boundingBox -> Y += (FrameHeight - MaxY ) * 0.5 ;
715
+ }
716
+ break ;
717
+ case StringAlignmentFar :
718
+ if (format -> formatFlags & StringFormatFlagsDirectionVertical ) {
719
+ boundingBox -> X += (FrameHeight - MaxY );
720
+ } else {
721
+ boundingBox -> Y += (FrameHeight - MaxY );
722
+ }
723
+ break ;
724
+ }
725
+
726
+ switch (AlignHorz ) {
727
+ case StringAlignmentCenter :
728
+ if (format -> formatFlags & StringFormatFlagsDirectionVertical ) {
729
+ boundingBox -> Y += (FrameWidth - MaxX ) * 0.5 ;
730
+ } else {
731
+ boundingBox -> X += (FrameWidth - MaxX ) * 0.5 ;
732
+ }
733
+ break ;
734
+ case StringAlignmentFar :
735
+ if (format -> formatFlags & StringFormatFlagsDirectionVertical ) {
736
+ boundingBox -> Y += (FrameWidth - MaxX );
737
+ } else {
738
+ boundingBox -> X += (FrameWidth - MaxX );
739
+ }
740
+ break ;
741
+ }
708
742
}
709
743
710
744
if (codepointsFitted ) {
@@ -727,6 +761,44 @@ MeasureString (GpGraphics *graphics, GDIPCONST WCHAR *stringUnicode, int *length
727
761
* linesFilled = floor (height / LineHeight );
728
762
}
729
763
764
+ if (AlignHorz != StringAlignmentNear || AlignVert != StringAlignmentNear ) {
765
+ // Update alignment
766
+ int length = 0 ;
767
+ int current_line_length = 0 ;
768
+ for (i = 0 ; i < StringLen ; i ++ ) {
769
+ if (i == current_line_length ) {
770
+ length = StringDetails [i ].LineLen ;
771
+ current_line_length = min (length + i , StringLen );
772
+ }
773
+
774
+ switch (AlignHorz ) {
775
+ case StringAlignmentNear :
776
+ break ;
777
+ case StringAlignmentCenter :
778
+ if ((current_line_length == 1 ) || (StringDetails [current_line_length - 1 ].PosX > 0 )) {
779
+ StringDetails [i ].PosX += (FrameWidth - StringDetails [current_line_length - 1 ].PosX -
780
+ StringDetails [current_line_length - 1 ].Width ) / 2 ;
781
+ }
782
+ break ;
783
+ case StringAlignmentFar :
784
+ StringDetails [i ].PosX += FrameWidth - StringDetails [current_line_length - 1 ].PosX -
785
+ StringDetails [current_line_length - 1 ].Width ;
786
+ break ;
787
+ }
788
+
789
+ switch (AlignVert ) {
790
+ case StringAlignmentNear :
791
+ break ;
792
+ case StringAlignmentCenter :
793
+ StringDetails [i ].PosY += (FrameHeight - MaxY ) / 2 ;
794
+ break ;
795
+ case StringAlignmentFar :
796
+ StringDetails [i ].PosY += FrameHeight - MaxY ;
797
+ break ;
798
+ }
799
+ }
800
+ }
801
+
730
802
/* if asked, supply extra data to be reused when drawing the same string */
731
803
if (data ) {
732
804
data -> align_horz = AlignHorz ;
@@ -813,55 +885,13 @@ DrawString (GpGraphics *graphics, GDIPCONST WCHAR *stringUnicode, int length, GD
813
885
814
886
if ((fmt -> formatFlags & StringFormatFlagsDirectionVertical )== 0 ) {
815
887
CursorX = rc -> X + StringDetails [i ].PosX ;
816
- switch (AlignHorz ) {
817
- case StringAlignmentNear :
818
- break ;
819
- case StringAlignmentCenter :
820
- /* PosX isn't calculated if the char is out of the bounding box (#79573/#79685) */
821
- if ((current_line_length == 1 ) || (StringDetails [current_line_length - 1 ].PosX > 0 )) {
822
- CursorX += (rc -> Width - StringDetails [current_line_length - 1 ].PosX -
823
- StringDetails [current_line_length - 1 ].Width ) / 2 ;
824
- }
825
- /* which means that the line is too long so no centering is required */
826
- break ;
827
- case StringAlignmentFar :
828
- CursorX += rc -> Width - StringDetails [current_line_length - 1 ].PosX -
829
- StringDetails [current_line_length - 1 ].Width ;
830
- break ;
831
- }
832
-
833
- switch (AlignVert ) {
834
- case StringAlignmentNear : CursorY = rc -> Y + StringDetails [i ].PosY + LineHeight ; break ;
835
- case StringAlignmentCenter : CursorY = rc -> Y + (rc -> Height - MaxY )/2 + StringDetails [i ].PosY + LineHeight ; break ;
836
- case StringAlignmentFar : CursorY = rc -> Y + rc -> Height - MaxY + StringDetails [i ].PosY + LineHeight ; break ;
837
- }
888
+ CursorY = rc -> Y + StringDetails [i ].PosY + LineHeight ;
838
889
839
890
gdip_cairo_move_to (graphics , CursorX , CursorY , FALSE, TRUE);
840
891
cairo_show_text (graphics -> ct , (const char * ) String );
841
892
} else {
842
- CursorY = rc -> Y ;
843
- switch (AlignHorz ) {
844
- case StringAlignmentNear :
845
- break ;
846
- case StringAlignmentCenter :
847
- /* PosX isn't calculated if the char is out of the bounding box (#79573/#79685) */
848
- if ((current_line_length == 1 ) || (StringDetails [current_line_length - 1 ].PosX > 0 )) {
849
- CursorY += (rc -> Height - StringDetails [current_line_length - 1 ].PosX -
850
- StringDetails [current_line_length - 1 ].Width ) / 2 ;
851
- }
852
- /* which means that the line is too long so no centering is required */
853
- break ;
854
- case StringAlignmentFar :
855
- CursorY += rc -> Height - StringDetails [current_line_length - 1 ].PosX -
856
- StringDetails [current_line_length - 1 ].Width ;
857
- break ;
858
- }
859
-
860
- switch (AlignVert ) {
861
- case StringAlignmentNear : CursorX = rc -> X + StringDetails [i ].PosX + StringDetails [i ].PosY ; break ;
862
- case StringAlignmentCenter : CursorX = rc -> X + StringDetails [i ].PosX + (rc -> Width - MaxY )/2 + StringDetails [i ].PosY ; break ;
863
- case StringAlignmentFar : CursorX = rc -> X + StringDetails [i ].PosX + rc -> Width - MaxY + StringDetails [i ].PosY ; break ;
864
- }
893
+ CursorY = rc -> Y + StringDetails [i ].PosX ;
894
+ CursorX = rc -> X + StringDetails [i ].PosY ;
865
895
866
896
/* Rotate text for vertical drawing */
867
897
cairo_save (graphics -> ct );
@@ -915,48 +945,23 @@ DrawString (GpGraphics *graphics, GDIPCONST WCHAR *stringUnicode, int length, GD
915
945
if (fmt -> hotkeyPrefix == HotkeyPrefixShow && data -> has_hotkeys ) {
916
946
GpStringDetailStruct * CurrentDetail = StringDetails ;
917
947
for (i = 0 ; i < StringLen ; i ++ ) {
918
- if (CurrentDetail -> Flags & STRING_DETAIL_LINESTART ) {
948
+ if (CurrentDetail -> Flags & STRING_DETAIL_HOTKEY ) {
919
949
if ((fmt -> formatFlags & StringFormatFlagsDirectionVertical )== 0 ) {
920
- switch (AlignHorz ) {
921
- case StringAlignmentNear : CursorX = rc -> X ; break ;
922
- case StringAlignmentCenter : CursorX = rc -> X + (rc -> Width - StringDetails [i + StringDetails [i ].LineLen - 1 ].PosX - StringDetails [i + StringDetails [i ].LineLen - 1 ].Width )/2 ; break ;
923
- case StringAlignmentFar : CursorX = rc -> X + rc -> Width - StringDetails [i + StringDetails [i ].LineLen - 1 ].PosX - StringDetails [i + StringDetails [i ].LineLen - 1 ].Width ; break ;
924
- }
925
-
926
- switch (AlignVert ) {
927
- case StringAlignmentNear : CursorY = rc -> Y + StringDetails [i ].PosY + LineHeight ; break ;
928
- case StringAlignmentCenter : CursorY = rc -> Y + (rc -> Height - MaxY )/2 + StringDetails [i ].PosY + LineHeight ; break ;
929
- case StringAlignmentFar : CursorY = rc -> Y + rc -> Height - MaxY + StringDetails [i ].PosY + LineHeight ; break ;
930
- }
950
+ CursorX = rc -> X + StringDetails [i ].PosX ;
951
+ CursorY = rc -> Y + StringDetails [i ].PosY + LineHeight ;
931
952
} else {
932
- switch (AlignHorz ) {
933
- case StringAlignmentNear : CursorY = rc -> Y ; break ;
934
- case StringAlignmentCenter : CursorY = rc -> Y + (rc -> Height - StringDetails [i + StringDetails [i ].LineLen - 1 ].PosX - StringDetails [i + StringDetails [i ].LineLen - 1 ].Width )/2 ; break ;
935
- case StringAlignmentFar : CursorY = rc -> Y + rc -> Height - StringDetails [i + StringDetails [i ].LineLen - 1 ].PosX - StringDetails [i + StringDetails [i ].LineLen - 1 ].Width ; break ;
936
- }
937
-
938
- switch (AlignVert ) {
939
- case StringAlignmentNear : CursorX = rc -> X + StringDetails [i ].PosY ; break ;
940
- case StringAlignmentCenter : CursorX = rc -> X + (rc -> Width - MaxY )/2 + StringDetails [i ].PosY ; break ;
941
- case StringAlignmentFar : CursorX = rc -> X + rc -> Width - MaxY + StringDetails [i ].PosY ; break ;
942
- }
953
+ CursorY = rc -> Y + StringDetails [i ].PosX ;
954
+ CursorX = rc -> X + StringDetails [i ].PosY ;
943
955
}
944
- }
945
956
946
- if (CurrentDetail -> Flags & STRING_DETAIL_HOTKEY ) {
947
957
if ((fmt -> formatFlags & StringFormatFlagsDirectionVertical )== 0 ) {
948
- CursorX += CurrentDetail -> PosX ;
949
958
cairo_set_line_width (graphics -> ct , 1 );
950
-
951
- gdip_cairo_move_to (graphics , (int )(CursorX ), (int )(CursorY + FontExtent .descent /2 ), FALSE, TRUE);
952
- gdip_cairo_line_to (graphics , (int )(CursorX + CurrentDetail -> Width ), (int )(CursorY + FontExtent .descent /2 ), FALSE, TRUE);
959
+ gdip_cairo_move_to (graphics , (int )(CursorX ), (int )(CursorY + FontExtent .descent ), FALSE, TRUE);
960
+ gdip_cairo_line_to (graphics , (int )(CursorX + CurrentDetail -> Width ), (int )(CursorY + FontExtent .descent ), FALSE, TRUE);
953
961
cairo_stroke (graphics -> ct );
954
- CursorX -= CurrentDetail -> PosX ;
955
962
} else {
956
- CursorY += CurrentDetail -> PosX ;
957
- gdip_cairo_move_to (graphics , (int )(CursorX - FontExtent .descent /2 ), (int )(CursorY ), FALSE, TRUE);
958
- gdip_cairo_line_to (graphics , (int )(CursorX - FontExtent .descent /2 ), (int )(CursorY + CurrentDetail -> Width ), FALSE, TRUE);
959
- CursorY -= CurrentDetail -> PosX ;
963
+ gdip_cairo_move_to (graphics , (int )(CursorX - FontExtent .descent ), (int )(CursorY ), FALSE, TRUE);
964
+ gdip_cairo_line_to (graphics , (int )(CursorX - FontExtent .descent ), (int )(CursorY + CurrentDetail -> Width ), FALSE, TRUE);
960
965
}
961
966
}
962
967
CurrentDetail ++ ;
@@ -1164,13 +1169,13 @@ cairo_MeasureCharacterRanges (GpGraphics *graphics, GDIPCONST WCHAR *stringUnico
1164
1169
continue ;
1165
1170
1166
1171
if (format -> formatFlags & StringFormatFlagsDirectionVertical ) {
1167
- charRect .X = StringDetails [j ].PosY ;
1168
- charRect .Y = StringDetails [j ].PosX ;
1172
+ charRect .X = layoutRect -> X + StringDetails [j ].PosY ;
1173
+ charRect .Y = layoutRect -> Y + StringDetails [j ].PosX ;
1169
1174
charRect .Width = lineHeight ;
1170
1175
charRect .Height = StringDetails [j ].Width ;
1171
1176
} else {
1172
- charRect .X = StringDetails [j ].PosX ;
1173
- charRect .Y = StringDetails [j ].PosY ;
1177
+ charRect .X = layoutRect -> X + StringDetails [j ].PosX ;
1178
+ charRect .Y = layoutRect -> Y + StringDetails [j ].PosY ;
1174
1179
charRect .Width = StringDetails [j ].Width ;
1175
1180
charRect .Height = lineHeight ;
1176
1181
}
0 commit comments