Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(562)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/content/TitleBitmapFactory.java

Issue 836123007: Use Math.ceil() instead of FloatMath.ceil() in TitleBitmapFactory class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.compositor.layouts.content; 5 package org.chromium.chrome.browser.compositor.layouts.content;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.res.Resources; 8 import android.content.res.Resources;
9 import android.graphics.Bitmap; 9 import android.graphics.Bitmap;
10 import android.graphics.Canvas; 10 import android.graphics.Canvas;
11 import android.graphics.Paint; 11 import android.graphics.Paint;
12 import android.graphics.Paint.FontMetrics; 12 import android.graphics.Paint.FontMetrics;
13 import android.graphics.drawable.BitmapDrawable; 13 import android.graphics.drawable.BitmapDrawable;
14 import android.graphics.drawable.Drawable; 14 import android.graphics.drawable.Drawable;
15 import android.text.Layout; 15 import android.text.Layout;
16 import android.text.TextPaint; 16 import android.text.TextPaint;
17 import android.text.TextUtils; 17 import android.text.TextUtils;
18 import android.util.FloatMath;
19 import android.util.Log; 18 import android.util.Log;
20 import android.view.InflateException; 19 import android.view.InflateException;
21 20
22 import org.chromium.chrome.R; 21 import org.chromium.chrome.R;
23 22
24 /** 23 /**
25 * A factory that creates text and favicon bitmaps. This is only relevant for th e phone tab 24 * A factory that creates text and favicon bitmaps. This is only relevant for th e phone tab
26 * switcher. 25 * switcher.
27 */ 26 */
28 public class TitleBitmapFactory { 27 public class TitleBitmapFactory {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); 65 mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
67 mTextPaint.setColor(textColor); 66 mTextPaint.setColor(textColor);
68 if (shadowXOffset != 0 && shadowYOffset != 0) { 67 if (shadowXOffset != 0 && shadowYOffset != 0) {
69 mTextPaint.setShadowLayer(0.001f, shadowXOffset, shadowYOffset, shad owColor); 68 mTextPaint.setShadowLayer(0.001f, shadowXOffset, shadowYOffset, shad owColor);
70 } 69 }
71 mTextPaint.setTextSize(adjustedTextSize); 70 mTextPaint.setTextSize(adjustedTextSize);
72 mTextPaint.setFakeBoldText(fakeBoldText); 71 mTextPaint.setFakeBoldText(fakeBoldText);
73 mTextPaint.density = res.getDisplayMetrics().density; 72 mTextPaint.density = res.getDisplayMetrics().density;
74 73
75 FontMetrics textFontMetrics = mTextPaint.getFontMetrics(); 74 FontMetrics textFontMetrics = mTextPaint.getFontMetrics();
76 mTextHeight = FloatMath.ceil(textFontMetrics.bottom - textFontMetrics.to p); 75 mTextHeight = (float) Math.ceil(textFontMetrics.bottom - textFontMetrics .top);
77 mTextYOffset = -textFontMetrics.top; 76 mTextYOffset = -textFontMetrics.top;
78 77
79 mFaviconDimension = res.getDimensionPixelSize(R.dimen.compositor_tab_tit le_favicon_size); 78 mFaviconDimension = res.getDimensionPixelSize(R.dimen.compositor_tab_tit le_favicon_size);
80 mViewHeight = (int) Math.max(mFaviconDimension, mTextHeight); 79 mViewHeight = (int) Math.max(mFaviconDimension, mTextHeight);
81 80
82 int width = res.getDisplayMetrics().widthPixels; 81 int width = res.getDisplayMetrics().widthPixels;
83 int height = res.getDisplayMetrics().heightPixels; 82 int height = res.getDisplayMetrics().heightPixels;
84 mMaxWidth = (int) (TITLE_WIDTH_PERCENTAGE * Math.max(width, height)); 83 mMaxWidth = (int) (TITLE_WIDTH_PERCENTAGE * Math.max(width, height));
85 84
86 // Set the favicon dimension here. 85 // Set the favicon dimension here.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 * Generates the title bitmap. 122 * Generates the title bitmap.
124 * 123 *
125 * @param context Android's UI context. 124 * @param context Android's UI context.
126 * @param title The title of the tab. 125 * @param title The title of the tab.
127 * @return The Bitmap with the title. 126 * @return The Bitmap with the title.
128 */ 127 */
129 public Bitmap getTitleBitmap(Context context, String title) { 128 public Bitmap getTitleBitmap(Context context, String title) {
130 try { 129 try {
131 boolean drawText = !TextUtils.isEmpty(title); 130 boolean drawText = !TextUtils.isEmpty(title);
132 int textWidth = 131 int textWidth =
133 drawText ? (int) FloatMath.ceil(Layout.getDesiredWidth(title , mTextPaint)) : 0; 132 drawText ? (int) Math.ceil(Layout.getDesiredWidth(title, mTe xtPaint)) : 0;
134 // Minimum 1 width bitmap to avoid createBitmap function's IllegalAr gumentException, 133 // Minimum 1 width bitmap to avoid createBitmap function's IllegalAr gumentException,
135 // when textWidth == 0. 134 // when textWidth == 0.
136 Bitmap b = Bitmap.createBitmap(Math.max(Math.min(mMaxWidth, textWidt h), 1), mViewHeight, 135 Bitmap b = Bitmap.createBitmap(Math.max(Math.min(mMaxWidth, textWidt h), 1), mViewHeight,
137 Bitmap.Config.ARGB_8888); 136 Bitmap.Config.ARGB_8888);
138 Canvas c = new Canvas(b); 137 Canvas c = new Canvas(b);
139 if (drawText) { 138 if (drawText) {
140 c.drawText(title, 0, title.length(), 0, 139 c.drawText(title, 0, title.length(), 0,
141 Math.round((mViewHeight - mTextHeight) / 2.0f + mTextYOf fset), mTextPaint); 140 Math.round((mViewHeight - mTextHeight) / 2.0f + mTextYOf fset), mTextPaint);
142 } 141 }
143 return b; 142 return b;
144 } catch (OutOfMemoryError ex) { 143 } catch (OutOfMemoryError ex) {
145 Log.w(TAG, "OutOfMemoryError while building title texture."); 144 Log.w(TAG, "OutOfMemoryError while building title texture.");
146 } catch (InflateException ex) { 145 } catch (InflateException ex) {
147 Log.w(TAG, "InflateException while building title texture."); 146 Log.w(TAG, "InflateException while building title texture.");
148 } 147 }
149 148
150 return null; 149 return null;
151 } 150 }
152 } 151 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698