1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.gallery3d.glrenderer;
18
19import android.graphics.Bitmap;
20import android.graphics.Canvas;
21import android.text.Layout;
22import android.text.StaticLayout;
23import android.text.TextPaint;
24
25
26// MultiLineTexture is a texture shows the content of a specified String.
27//
28// To create a MultiLineTexture, use the newInstance() method and specify
29// the String, the font size, and the color.
30class MultiLineTexture extends CanvasTexture {
31    private final Layout mLayout;
32
33    private MultiLineTexture(Layout layout) {
34        super(layout.getWidth(), layout.getHeight());
35        mLayout = layout;
36    }
37
38    public static MultiLineTexture newInstance(
39            String text, int maxWidth, float textSize, int color,
40            Layout.Alignment alignment) {
41        TextPaint paint = StringTexture.getDefaultPaint(textSize, color);
42        Layout layout = new StaticLayout(text, 0, text.length(), paint,
43                maxWidth, alignment, 1, 0, true, null, 0);
44
45        return new MultiLineTexture(layout);
46    }
47
48    @Override
49    protected void onDraw(Canvas canvas, Bitmap backing) {
50        mLayout.draw(canvas);
51    }
52}
53