Skip to content

Commit

Permalink
Minor Fixes (#40)
Browse files Browse the repository at this point in the history
* Fixed textbackground

* Changed name of font api
  • Loading branch information
vinaygaba authored May 29, 2017
1 parent 926be13 commit 0a09f17
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ private void addTextToBitmap(RubberStampConfig config, Canvas canvas, int baseBi
Paint backgroundPaint = new Paint();
backgroundPaint.setColor(backgroundColor);
canvas.drawRect(positionX - BACKGROUND_MARGIN,
positionY - bounds.height() - BACKGROUND_MARGIN,
(positionX + rubberStampMeasuredWidth + BACKGROUND_MARGIN),
positionY + BACKGROUND_MARGIN,
positionY - bounds.height() - paint.getFontMetrics().descent - BACKGROUND_MARGIN,
(positionX + rubberStampMeasuredWidth + config.getTextShadowXOffset() + BACKGROUND_MARGIN),
positionY + config.getTextShadowYOffset() + paint.getFontMetrics().descent + BACKGROUND_MARGIN,
backgroundPaint);
}
canvas.drawText(rubberStampString, positionX , positionY, paint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public RubberStampConfigBuilder textBackgroundColor(final int color) {
return this;
}

public RubberStampConfigBuilder typeFacePath(final String typeFacePath) {
public RubberStampConfigBuilder textFont(final String typeFacePath) {
this.mTypeFacePath = typeFacePath;
return this;
}
Expand Down
Binary file added sample/src/main/assets/fonts/bebasneue.otf
Binary file not shown.
Binary file added sample/src/main/assets/fonts/caviardreams.ttf
Binary file not shown.
Binary file added sample/src/main/assets/fonts/champagne.ttf
Binary file not shown.
19 changes: 15 additions & 4 deletions sample/src/main/java/com/vinaygaba/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ public class MainActivity extends AppCompatActivity {
private RadioGroup mRadioGroup;
private Bitmap mBaseBitmap;
private Button mGenerateButton;
private SeekBar mAlphaSeekBar;
private SeekBar mRotationSeekBar;
private SeekBar mTextSizeSeekBar;
private Spinner mRubberStampPosition;
private SeekBar mAlphaSeekBar, mRotationSeekBar, mTextSizeSeekBar;
private Spinner mRubberStampPosition, mTextFonts;
private LinearLayout mTextLayoutWrapper;
private TextView mTextColor, mTextBackgroundColor;
private EditText mRubberStampText;
Expand Down Expand Up @@ -77,6 +75,7 @@ public void init() {
mRotationSeekBar = (SeekBar) findViewById(R.id.rotationSeekBar);
mTextSizeSeekBar = (SeekBar) findViewById(R.id.textSizeSeekBar);
mRubberStampPosition = (Spinner) findViewById(R.id.rubberStampPositions);
mTextFonts = (Spinner) findViewById(R.id.textFonts);
mTextLayoutWrapper = (LinearLayout) findViewById(R.id.textLayoutWrapper);
mTextColor = (TextView) findViewById(R.id.textColor);
mTextBackgroundColor = (TextView) findViewById(R.id.textBackgroundColor);
Expand Down Expand Up @@ -167,6 +166,7 @@ public void generateRubberStamp() {
.rubberStampPosition(rubberStampPosition)
.build();
} else {
String path = convertFontPositionToPath(mTextFonts.getSelectedItemPosition());
Shader shader = getShader();
config = new RubberStampConfig.RubberStampConfigBuilder()
.base(mBaseBitmap)
Expand All @@ -177,6 +177,7 @@ public void generateRubberStamp() {
.textColor(mTextColorValue)
.textBackgroundColor(mTextBackgroundColorValue)
.textShader(shader)
.textFont(path)
.textSize(mTextSizeSeekBar.getProgress())
.build();
}
Expand Down Expand Up @@ -227,6 +228,16 @@ private RubberStampPosition convertToRubberStampPosition(int selectedItemPositio
}
}

public String convertFontPositionToPath(int position) {
String basePath = "fonts/";
switch (position) {
case 0: return basePath + "bebasneue.otf";
case 1: return basePath + "caviardreams.ttf";
case 2: return basePath + "champagne.ttf";
default: return basePath + "bebasneue.otf";
}
}

public Observable<Bitmap> getBitmap(final RubberStamp rubberStamp,
final RubberStampConfig config) {
return Observable.defer(new Func0<Observable<Bitmap>>() {
Expand Down
14 changes: 3 additions & 11 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,9 @@
</string-array>

<string-array name="fonts_array">
<item>Top Left</item>
<item>Top Center</item>
<item>Top Right</item>
<item>Center Left</item>
<item>Center</item>
<item>Center Right</item>
<item>Bottom Left</item>
<item>Bottom Center</item>
<item>Bottom Right</item>
<item>Custom</item>
<item>Tile</item>
<item>Bebas Neue</item>
<item>Caviar Dreams</item>
<item>Champagne</item>
</string-array>

</resources>

0 comments on commit 0a09f17

Please sign in to comment.