flutter_flutter/include/minikin/FontCollection.h
Seigo Nonaka bbdd73ec07 Support Variation Selector in font selection.
This CL contains the following changes:
- Add a variation selector argument into getFamilyForChar to be able to
  select fonts which support variation selector.
- In case no fonts support the codepoint and variation selector pair,
  add a fallback rule which selects font family with ignoring variation
  selector.
- Change FontCollection::itemize to not change the font family
  immediately preceding a variation selector.
- Introduce unit tests for variation selectors.

With this CL, TextView can render the variation selectors correctly.

Bug: 11256006
Change-Id: I22ce0e9eadc941f84e3a9b23462f194e51dd7180
2015-10-20 12:34:40 +09:00

87 lines
2.5 KiB
C++

/*
* 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_COLLECTION_H
#define MINIKIN_FONT_COLLECTION_H
#include <vector>
#include <minikin/MinikinRefCounted.h>
#include <minikin/MinikinFont.h>
#include <minikin/FontFamily.h>
namespace android {
class FontCollection : public MinikinRefCounted {
public:
explicit FontCollection(const std::vector<FontFamily*>& typefaces);
~FontCollection();
struct Run {
FakedFont fakedFont;
int start;
int end;
};
void itemize(const uint16_t *string, size_t string_length, FontStyle style,
std::vector<Run>* result) const;
// Get the base font for the given style, useful for font-wide metrics.
MinikinFont* baseFont(FontStyle style);
// Get base font with fakery information (fake bold could affect metrics)
FakedFont baseFontFaked(FontStyle style);
uint32_t getId() const;
// Calls each managed font family's FontFamily::purgeHbFontCache method.
// Caller should acquire a lock before calling the method.
void purgeFontFamilyHbFontCache() const;
private:
static const int kLogCharsPerPage = 8;
static const int kPageMask = (1 << kLogCharsPerPage) - 1;
struct Range {
size_t start;
size_t end;
};
FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, FontLanguage lang, int variant) const;
// static for allocating unique id's
static uint32_t sNextId;
// unique id for this font collection (suitable for cache key)
uint32_t mId;
// Highest UTF-32 code point that can be mapped
uint32_t mMaxChar;
// This vector has ownership of the bitsets and typeface objects.
std::vector<FontFamily*> mFamilies;
// This vector contains pointers into mInstances
std::vector<FontFamily*> mFamilyVec;
// These are offsets into mInstanceVec, one range per page
std::vector<Range> mRanges;
};
} // namespace android
#endif // MINIKIN_FONT_COLLECTION_H