diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 8a6e7725d0..6d1de2fbd2 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -23,25 +23,9 @@ #include #include -#include namespace minikin { -// 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 GlyphBitmap& 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 @@ -95,8 +79,6 @@ public: int bidiFlags, const FontStyle &style, const MinikinPaint &paint, const std::shared_ptr& collection, float* advances); - void draw(minikin::Bitmap*, int x0, int y0, float size) const; - // public accessors size_t nGlyphs() const; const MinikinFont* getFont(int i) const; diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 52263f529a..01af786aa6 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -81,8 +81,6 @@ struct MinikinRect { void join(const MinikinRect& r); }; -class MinikinFontFreeType; - // Callback for freeing data typedef void (*MinikinDestroyFunc) (void* data); diff --git a/engine/src/flutter/include/minikin/MinikinFontFreeType.h b/engine/src/flutter/include/minikin/MinikinFontFreeType.h deleted file mode 100644 index 37333e5f37..0000000000 --- a/engine/src/flutter/include/minikin/MinikinFontFreeType.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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_FONT_FREETYPE_H -#define MINIKIN_FONT_FREETYPE_H - -#include -#include FT_FREETYPE_H -#include FT_TRUETYPE_TABLES_H - -#include - -// An abstraction for platform fonts, allowing Minikin to be used with -// multiple actual implementations of fonts. - -namespace minikin { - -struct GlyphBitmap { - uint8_t *buffer; - int width; - int height; - int left; - int top; -}; - -class MinikinFontFreeType : public MinikinFont { -public: - explicit MinikinFontFreeType(FT_Face typeface); - - ~MinikinFontFreeType(); - - float GetHorizontalAdvance(uint32_t glyph_id, - const MinikinPaint &paint) const; - - void GetBounds(MinikinRect* bounds, uint32_t glyph_id, - const MinikinPaint& paint) const; - - const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); - - const std::vector& GetAxes() const { - return mAxes; - } - - // TODO: provide access to raw data, as an optimization. - - // Not a virtual method, as the protocol to access rendered - // glyph bitmaps is probably different depending on the - // backend. - bool Render(uint32_t glyph_id, - const MinikinPaint &paint, GlyphBitmap *result); - - MinikinFontFreeType* GetFreeType(); - -private: - FT_Face mTypeface; - static int32_t sIdCounter; - std::vector mAxes; -}; - -} // namespace minikin - -#endif // MINIKIN_FONT_FREETYPE_H diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index be5301218a..67a478a7c7 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -33,13 +33,11 @@ minikin_src_files := \ Measurement.cpp \ MinikinInternal.cpp \ MinikinFont.cpp \ - MinikinFontFreeType.cpp \ SparseBitSet.cpp \ WordBreaker.cpp minikin_c_includes := \ external/harfbuzz_ng/src \ - external/freetype/include \ frameworks/minikin/include \ $(intermediates) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 0a318bdccd..1f2fbc4457 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -39,7 +39,6 @@ #include "HbFontCache.h" #include "LayoutUtils.h" #include "MinikinInternal.h" -#include #include using std::string; @@ -47,44 +46,6 @@ using std::vector; namespace minikin { -Bitmap::Bitmap(int width, int height) : width(width), height(height) { - buf = new uint8_t[width * height](); -} - -Bitmap::~Bitmap() { - delete[] buf; -} - -void Bitmap::writePnm(std::ofstream &o) const { - o << "P5" << std::endl; - o << width << " " << height << std::endl; - o << "255" << std::endl; - o.write((const char *)buf, width * height); - o.close(); -} - -void Bitmap::drawGlyph(const GlyphBitmap& bitmap, int x, int y) { - int bmw = bitmap.width; - int bmh = bitmap.height; - x += bitmap.left; - y -= bitmap.top; - int x0 = std::max(0, x); - int x1 = std::min(width, x + bmw); - int y0 = std::max(0, y); - int y1 = std::min(height, y + bmh); - const unsigned char* src = bitmap.buffer + (y0 - y) * bmw + (x0 - x); - uint8_t* dst = buf + y0 * width; - for (int yy = y0; yy < y1; yy++) { - for (int xx = x0; xx < x1; xx++) { - int pixel = (int)dst[xx] + (int)src[xx - x]; - pixel = pixel > 0xff ? 0xff : pixel; - dst[xx] = pixel; - } - src += bmw; - dst += width; - } -} - const int kDirection_Mask = 0x1; struct LayoutContext { @@ -1091,34 +1052,6 @@ void Layout::appendLayout(Layout* src, size_t start, float extraAdvance) { } } -void Layout::draw(minikin::Bitmap* surface, int x0, int y0, float size) const { - /* - TODO: redo as MinikinPaint settings - if (mProps.hasTag(minikinHinting)) { - int hintflags = mProps.value(minikinHinting).getIntValue(); - if (hintflags & 1) load_flags |= FT_LOAD_NO_HINTING; - if (hintflags & 2) load_flags |= FT_LOAD_NO_AUTOHINT; - } - */ - for (size_t i = 0; i < mGlyphs.size(); i++) { - const LayoutGlyph& glyph = mGlyphs[i]; - MinikinFont* mf = mFaces[glyph.font_ix].font; - MinikinFontFreeType* face = static_cast(mf); - GlyphBitmap glyphBitmap; - MinikinPaint paint; - paint.size = size; - bool ok = face->Render(glyph.glyph_id, paint, &glyphBitmap); -#ifdef VERBOSE_DEBUG - ALOGD("glyphBitmap.width=%d, glyphBitmap.height=%d (%d, %d) x=%f, y=%f, ok=%d", - glyphBitmap.width, glyphBitmap.height, glyphBitmap.left, glyphBitmap.top, glyph.x, glyph.y, ok); -#endif - if (ok) { - surface->drawGlyph(glyphBitmap, - x0 + int(floor(glyph.x + 0.5)), y0 + int(floor(glyph.y + 0.5))); - } - } -} - size_t Layout::nGlyphs() const { return mGlyphs.size(); } diff --git a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp deleted file mode 100644 index 6f56a8dd55..0000000000 --- a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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. - */ - -// Implementation of MinikinFont abstraction specialized for FreeType - -#include - -#include -#include FT_FREETYPE_H -#include FT_TRUETYPE_TABLES_H -#include FT_ADVANCES_H - -#include - -namespace minikin { - -int32_t MinikinFontFreeType::sIdCounter = 0; - -MinikinFontFreeType::MinikinFontFreeType(FT_Face typeface) : - MinikinFont(sIdCounter++), - mTypeface(typeface) { -} - -MinikinFontFreeType::~MinikinFontFreeType() { - FT_Done_Face(mTypeface); -} - -float MinikinFontFreeType::GetHorizontalAdvance(uint32_t glyph_id, - const MinikinPaint &paint) const { - FT_Set_Pixel_Sizes(mTypeface, 0, paint.size); - FT_UInt32 flags = FT_LOAD_DEFAULT; // TODO: respect hinting settings - FT_Fixed advance; - FT_Get_Advance(mTypeface, glyph_id, flags, &advance); - return advance * (1.0 / 65536); -} - -void MinikinFontFreeType::GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_id*/, - const MinikinPaint& /* paint */) const { - // TODO: NYI -} - -const void* MinikinFontFreeType::GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) { - FT_ULong ftsize = 0; - FT_Error error = FT_Load_Sfnt_Table(mTypeface, tag, 0, nullptr, &ftsize); - if (error != 0) { - return nullptr; - } - FT_Byte* buf = reinterpret_cast(malloc(ftsize)); - if (buf == nullptr) { - return nullptr; - } - error = FT_Load_Sfnt_Table(mTypeface, tag, 0, buf, &ftsize); - if (error != 0) { - free(buf); - return nullptr; - } - *destroy = free; - *size = ftsize; - return buf; -} - -bool MinikinFontFreeType::Render(uint32_t glyph_id, const MinikinPaint& /* paint */, - GlyphBitmap *result) { - FT_Error error; - FT_Int32 load_flags = FT_LOAD_DEFAULT; // TODO: respect hinting settings - error = FT_Load_Glyph(mTypeface, glyph_id, load_flags); - if (error != 0) { - return false; - } - error = FT_Render_Glyph(mTypeface->glyph, FT_RENDER_MODE_NORMAL); - if (error != 0) { - return false; - } - FT_Bitmap &bitmap = mTypeface->glyph->bitmap; - result->buffer = bitmap.buffer; - result->width = bitmap.width; - result->height = bitmap.rows; - result->left = mTypeface->glyph->bitmap_left; - result->top = mTypeface->glyph->bitmap_top; - return true; -} - -MinikinFontFreeType* MinikinFontFreeType::GetFreeType() { - return this; -} - -} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index 25406d0822..eca0107397 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -84,7 +84,6 @@ LOCAL_SRC_FILES += \ LOCAL_C_INCLUDES := \ $(LOCAL_PATH)/../../libs/minikin/ \ $(LOCAL_PATH)/../util \ - external/freetype/include \ external/harfbuzz_ng/src \ external/libxml2/include \ external/skia/src/core