diff options
author | Raph Levien <raph@google.com> | 2013-04-23 15:45:41 -0700 |
---|---|---|
committer | Raph Levien <raph@google.com> | 2013-04-25 12:23:57 -0700 |
commit | 9cc9bbe1461f359f0b27c5e7645c17dda001ab1d (patch) | |
tree | f7ef7ea18618b4be52dbc53a9b88fbdcb661a970 /include/minikin/Layout.h | |
parent | cd404cb5e1aed30b46a7af7ddb91ba6e126fe4c2 (diff) | |
download | android_frameworks_minikin-9cc9bbe1461f359f0b27c5e7645c17dda001ab1d.tar.gz android_frameworks_minikin-9cc9bbe1461f359f0b27c5e7645c17dda001ab1d.tar.bz2 android_frameworks_minikin-9cc9bbe1461f359f0b27c5e7645c17dda001ab1d.zip |
Initial commit of Minikin library
This is the initial draft of Minikin, a library intended to perform text
layout functions. This version does basic weight selection and font runs
for scripts, and also has a simple renderer for drawing into bitmaps,
but is lacking measurement, line breaking, and a number of other
important features. It also lacks caching and other performance
refinements.
Change-Id: I789a2e47d11d71202dc84b4751b51a5e2cd9c451
Diffstat (limited to 'include/minikin/Layout.h')
-rw-r--r-- | include/minikin/Layout.h | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/include/minikin/Layout.h b/include/minikin/Layout.h new file mode 100644 index 0000000..7a6c6cf --- /dev/null +++ b/include/minikin/Layout.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MINIKIN_LAYOUT_H +#define MINIKIN_LAYOUT_H + +#include <ft2build.h> +#include FT_FREETYPE_H + +#include <hb.h> + +#include <vector> + +#include <minikin/CssParse.h> +#include <minikin/FontCollection.h> + +namespace android { + +// The Bitmap class is for debugging. We'll probably move it out +// of here into a separate lightweight software rendering module +// (optional, as we'd hope most clients would do their own) +class Bitmap { +public: + Bitmap(int width, int height); + ~Bitmap(); + void writePnm(std::ofstream& o) const; + void drawGlyph(const FT_Bitmap& bitmap, int x, int y); +private: + int width; + int height; + uint8_t* buf; +}; + +struct LayoutGlyph { + // index into mFaces and mHbFonts vectors. We could imagine + // moving this into a run length representation, because it's + // more efficient for long strings, and we'll probably need + // something like that for paint attributes (color, underline, + // fake b/i, etc), as having those per-glyph is bloated. + int font_ix; + + unsigned int glyph_id; + float x; + float y; +}; + +class Layout { +public: + void dump() const; + void setFontCollection(const FontCollection *collection); + void doLayout(const uint16_t* buf, size_t nchars); + void draw(Bitmap*, int x0, int y0) const; + void setProperties(const std::string css); + + // This must be called before any invocations. + // TODO: probably have a factory instead + static void init(); +private: + // Find a face in the mFaces vector, or create a new entry + int findFace(FT_Face face); + + CssProperties mProps; // TODO: want spans + std::vector<LayoutGlyph> mGlyphs; + + // In future, this will be some kind of mapping from the + // identifier used to represent font-family to a font collection. + // But for the time being, it should be ok to have just one + // per layout. + const FontCollection *mCollection; + std::vector<FT_Face> mFaces; + std::vector<hb_font_t *> mHbFonts; +}; + +} // namespace android + +#endif // MINIKIN_LAYOUT_H |