Skip to content
This repository has been archived by the owner on Apr 27, 2019. It is now read-only.

StringDocumentLayout text alignment fix #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ public boolean onMeasure(IProgress<Float> progress, ICancel<Boolean> cancelled)

// Line fits, then don't wrap
if (wrappedWidth < width) {
float remainWidth = width - wrappedWidth;
switch (params.textAlignment) {
case CENTER: {
x += remainWidth / 2;
break;
}
case RIGHT: {
x += remainWidth;
break;
}
}

// activeCanvas.drawText(paragraph, x, y, paint);
tokensList.add(new SingleLine(lineNumber++, x, y, trimParagraph));
y += lineHeight;
Expand Down
4 changes: 4 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@
android:name="com.bluejamesbond.text.sample.test.ForceNoCacheXMLTest"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@android:style/Theme.NoTitleBar" />
<activity
android:name="com.bluejamesbond.text.sample.test.SingleWordTest"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@android:style/Theme.NoTitleBar" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.bluejamesbond.text.sample.test.QuoteSpanTest;
import com.bluejamesbond.text.sample.test.RTLTest;
import com.bluejamesbond.text.sample.test.ShortFormattedTextTest;
import com.bluejamesbond.text.sample.test.SingleWordTest;
import com.bluejamesbond.text.sample.test.TextUpdateTest;
import com.bluejamesbond.text.sample.test.TextViewTest;
import com.bluejamesbond.text.sample.test.WordSpacingTest;
Expand Down Expand Up @@ -87,7 +88,8 @@ public class TestList extends TestActivity {
ShortFormattedTextTest.class,
ImageSpanTest.class,
TextUpdateTest.class,
ForceNoCacheXMLTest.class
ForceNoCacheXMLTest.class,
SingleWordTest.class
};

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.bluejamesbond.text.sample.test;

import android.os.Bundle;

import com.bluejamesbond.text.DocumentView;
import com.bluejamesbond.text.sample.helper.TestActivity;
import com.bluejamesbond.text.style.TextAlignment;


public class SingleWordTest extends TestActivity {

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

DocumentView centerView = addDocumentView("Center", DocumentView.PLAIN_TEXT);
centerView.getDocumentLayoutParams().setTextAlignment(TextAlignment.CENTER);
}
}