Fix watermark

This commit is contained in:
Thomas 2022-10-24 10:59:31 +02:00
parent 4da83ef20a
commit c23be87ff4
2 changed files with 6 additions and 9 deletions

View file

@ -1189,12 +1189,10 @@ public class Helper {
*/ */
public static MultipartBody.Part getMultipartBodyWithWM(Context context, String waterMark, @NonNull String paramName, @NonNull Attachment attachment) { public static MultipartBody.Part getMultipartBodyWithWM(Context context, String waterMark, @NonNull String paramName, @NonNull Attachment attachment) {
File files = new File(attachment.local_path); File files = new File(attachment.local_path);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
float scale = sharedpreferences.getFloat(context.getString(R.string.SET_FONT_SCALE), 1.1f);
float textSize = 15; float textSize = 15;
Paint mPaint = new Paint(); Paint paint = new Paint();
mPaint.setTextSize(textSize); float textWidht = paint.measureText(waterMark);
float width = mPaint.measureText(waterMark, 0, waterMark.length()) * scale; float width = Helper.convertDpToPixel(textWidht, context);
try { try {
BitmapFactory.Options options = new BitmapFactory.Options(); BitmapFactory.Options options = new BitmapFactory.Options();
@ -1202,11 +1200,10 @@ public class Helper {
int w = options.outWidth; int w = options.outWidth;
int h = options.outHeight; int h = options.outHeight;
float valx = (float) 1.0 - ((Helper.convertDpToPixel(width, context) + 90)) / (float) w; float valx = (float) 1.0 - (float) width / (float) w;
if (valx < 0) if (valx < 0)
valx = 0; valx = 0;
float valy = (h - Helper.convertDpToPixel(textSize, context) - 30) / (float) h; float valy = (h - Helper.convertDpToPixel(textSize, context) - 10) / (float) h;
WatermarkText watermarkText = new WatermarkText(waterMark) WatermarkText watermarkText = new WatermarkText(waterMark)
.setPositionX(valx) .setPositionX(valx)
.setPositionY(valy) .setPositionY(valy)

View file

@ -147,7 +147,7 @@ public class ComposeWorker extends Worker {
} }
} }
} }
if (watermarkText == null) { if (watermarkText == null || watermarkText.trim().length() == 0) {
try { try {
BaseAccount account = new Account(context).getAccountByToken(dataPost.token); BaseAccount account = new Account(context).getAccountByToken(dataPost.token);
watermarkText = account.mastodon_account.username + "@" + account.instance; watermarkText = account.mastodon_account.username + "@" + account.instance;