diff --git a/Classes/pdGlyphCollection.cls b/Classes/pdGlyphCollection.cls index 86067c963e..231cf81c2b 100644 --- a/Classes/pdGlyphCollection.cls +++ b/Classes/pdGlyphCollection.cls @@ -1320,29 +1320,37 @@ Private Function CalculateGlyphPositions(ByRef boundingRect As RectF, ByVal hori 'Start with horizontal alignment If (horizontalAlignment <> StringAlignmentNear) Then - 'Because we kept a running tally of each line's width during the processing stages, it is easy - ' to calculate offsets now. - For curLine = 0 To numOfLines - 1 + 'Justified text is TODO + If (horizontalAlignment = StringAlignmentJustify) Then - 'For each line, replace its calculated line width with the difference between the bounding rect - ' and the actual size. - lineDiff = boundingRectRight - m_LineWidths(curLine) + 'Right/center alignment is much easier + Else + + 'Because we kept a running tally of each line's width during the processing stages, it is easy + ' to calculate offsets now. + For curLine = 0 To numOfLines - 1 + + 'For each line, replace its calculated line width with the difference between the bounding rect + ' and the actual size. + lineDiff = boundingRectRight - m_LineWidths(curLine) + + If (horizontalAlignment = StringAlignmentCenter) Then + hLineOffsets(curLine) = lineDiff * 0.5! + Else + hLineOffsets(curLine) = lineDiff + End If + + Next curLine + + 'Each line width tracker now contains the offset required to make alignment work. Apply it to each glyph in turn. + For curGlyph = 0 To m_NumOfGlyphs - 1 + With m_Glyphs(curGlyph) + .finalX = .finalX + hLineOffsets(.lineID) + End With + Next curGlyph + + End If - If (horizontalAlignment = StringAlignmentCenter) Then - hLineOffsets(curLine) = lineDiff * 0.5! - Else - hLineOffsets(curLine) = lineDiff - End If - - Next curLine - - 'Each line width tracker now contains the offset required to make alignment work. Apply it to each glyph in turn. - For curGlyph = 0 To m_NumOfGlyphs - 1 - With m_Glyphs(curGlyph) - .finalX = .finalX + hLineOffsets(.lineID) - End With - Next curGlyph - End If 'Next, vertical alignment diff --git a/Classes/pdTextRenderer.cls b/Classes/pdTextRenderer.cls index 265f319817..371326da6d 100644 --- a/Classes/pdTextRenderer.cls +++ b/Classes/pdTextRenderer.cls @@ -773,6 +773,8 @@ Private Function GetAlignmentStringFromUnit(ByVal srcValue As GP_StringAlignment GetAlignmentStringFromUnit = "center" ElseIf (srcValue = StringAlignmentFar) Then GetAlignmentStringFromUnit = "far" + ElseIf (srcValue = StringAlignmentJustify) Then + GetAlignmentStringFromUnit = "justify" Else InternalError "GetAlignmentStringFromUnit", "bad value: " & srcValue GetAlignmentStringFromUnit = "near" @@ -786,6 +788,8 @@ Private Function GetAlignmentUnitFromString(ByRef srcValue As String) As GP_Stri GetAlignmentUnitFromString = StringAlignmentCenter ElseIf (srcValue = "far") Then GetAlignmentUnitFromString = StringAlignmentFar + ElseIf (srcValue = "justify") Then + GetAlignmentUnitFromString = StringAlignmentJustify Else InternalError "GetAlignmentUnitFromString", "bad value: " & srcValue GetAlignmentUnitFromString = StringAlignmentNear @@ -826,6 +830,7 @@ Friend Function GetGenericTextProperty(ByVal desiredProperty As PD_TextProperty) Case ptp_HorizontalAlignment GetGenericTextProperty = m_HorizontalAlignment + If (m_RenderingEngine <> te_PhotoDemon) And (m_HorizontalAlignment >= StringAlignmentJustify) Then GetGenericTextProperty = StringAlignmentNear Case ptp_VerticalAlignment GetGenericTextProperty = m_VerticalAlignment @@ -988,7 +993,7 @@ Friend Function SetGenericTextProperty(ByVal desiredProperty As PD_TextProperty, If (m_HorizontalAlignment <> CLng(newValue)) Then m_HorizontalAlignment = CLng(newValue) SetGenericTextProperty = True - If (m_GDIPlusStringFormat <> 0) Then GdipSetStringFormatAlign m_GDIPlusStringFormat, m_HorizontalAlignment + If (m_GDIPlusStringFormat <> 0) And (m_HorizontalAlignment < StringAlignmentJustify) Then GdipSetStringFormatAlign m_GDIPlusStringFormat, m_HorizontalAlignment End If Case ptp_VerticalAlignment @@ -2090,8 +2095,9 @@ Private Function RenderTextToDIB_GDI(ByRef dstDIB As pdDIB, ByRef srcString As S Dim xOffset As Long, yOffset As Long Select Case m_HorizontalAlignment - - Case StringAlignmentNear + + 'Justified text does *not* work with this renderer + Case StringAlignmentNear, StringAlignmentJustify xOffset = 0 Case StringAlignmentCenter @@ -2153,6 +2159,10 @@ Private Function GetDrawTextAlignmentFlags() As Win32_DrawTextConstants Case StringAlignmentFar GetDrawTextAlignmentFlags = GetDrawTextAlignmentFlags Or DT_RIGHT + + 'PhotoDemon can render justified text, but Win32 cannot. + Case Else + GetDrawTextAlignmentFlags = GetDrawTextAlignmentFlags Or DT_LEFT End Select diff --git a/Forms/Toolpanel_TextBasic.frm b/Forms/Toolpanel_TextBasic.frm index c3717d800d..5beec2f396 100644 --- a/Forms/Toolpanel_TextBasic.frm +++ b/Forms/Toolpanel_TextBasic.frm @@ -142,8 +142,8 @@ Begin VB.Form toolpanel_TextBasic Left = 7950 TabIndex = 4 Top = 345 - Width = 1455 - _ExtentX = 2566 + Width = 1485 + _ExtentX = 2619 _ExtentY = 767 ColorScheme = 1 End diff --git a/Forms/Toolpanel_Typography.frm b/Forms/Toolpanel_Typography.frm index 8b53a8f347..59dc1646c9 100644 --- a/Forms/Toolpanel_Typography.frm +++ b/Forms/Toolpanel_Typography.frm @@ -589,14 +589,14 @@ Begin VB.Form toolpanel_TextAdvanced Left = 7950 TabIndex = 42 Top = 345 - Width = 1455 - _ExtentX = 2566 + Width = 1965 + _ExtentX = 3466 _ExtentY = 767 ColorScheme = 1 End Begin PhotoDemon.pdButtonStrip btsVAlignment Height = 435 - Left = 9510 + Left = 9960 TabIndex = 32 Top = 345 Width = 1455 @@ -610,8 +610,8 @@ Begin VB.Form toolpanel_TextAdvanced Left = 7920 TabIndex = 33 Top = 0 - Width = 3015 - _ExtentX = 5318 + Width = 3495 + _ExtentX = 6165 _ExtentY = 635 Caption = "alignment" Value = 0 'False @@ -1407,6 +1407,7 @@ Private Sub Form_Load() btsHAlignment.AddItem vbNullString, 0 btsHAlignment.AddItem vbNullString, 1 btsHAlignment.AddItem vbNullString, 2 + btsHAlignment.AddItem vbNullString, 3 btsVAlignment.AddItem vbNullString, 0 btsVAlignment.AddItem vbNullString, 1 @@ -2111,6 +2112,7 @@ Public Sub UpdateAgainstCurrentTheme() btsHAlignment.AssignImageToItem 0, "format_alignleft", , buttonSize, buttonSize, usePDResamplerInstead:=rf_Box btsHAlignment.AssignImageToItem 1, "format_aligncenter", , buttonSize, buttonSize, usePDResamplerInstead:=rf_Box btsHAlignment.AssignImageToItem 2, "format_alignright", , buttonSize, buttonSize, usePDResamplerInstead:=rf_Box + btsHAlignment.AssignImageToItem 3, "format_alignjustify", , buttonSize, buttonSize, usePDResamplerInstead:=rf_Box btsVAlignment.AssignImageToItem 0, "format_aligntop", , buttonSize, buttonSize, usePDResamplerInstead:=rf_Box btsVAlignment.AssignImageToItem 1, "format_alignmiddle", , buttonSize, buttonSize, usePDResamplerInstead:=rf_Box diff --git a/Modules/GDIPlus.bas b/Modules/GDIPlus.bas index cb5bef87bd..dfdfe80011 100644 --- a/Modules/GDIPlus.bas +++ b/Modules/GDIPlus.bas @@ -734,10 +734,13 @@ Public Enum GP_StringAlignment StringAlignmentNear = 0 StringAlignmentCenter = 1 StringAlignmentFar = 2 + + 'IMPORTANT NOTE: GDI+ cannot render justified text. This setting *ONLY* works with PhotoDemon's advanced text renderer. + StringAlignmentJustify = 3 End Enum #If False Then - Private Const StringAlignmentNear = 0, StringAlignmentCenter = 1, StringAlignmentFar = 2 + Private Const StringAlignmentNear = 0, StringAlignmentCenter = 1, StringAlignmentFar = 2, StringAlignmentJustify = 3 #End If Public Enum GP_Unit