* 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 <memory>
#include <unordered_set>
#include <vector>
#include <minikin/FontFamily.h>
#include <minikin/MinikinFont.h>
namespace minikin {
class FontCollection {
public:
explicit FontCollection(
const std::vector<std::shared_ptr<FontFamily>>& typefaces);
explicit FontCollection(std::shared_ptr<FontFamily>&& typeface);
class FallbackFontProvider {
public:
virtual ~FallbackFontProvider() = default;
virtual const std::shared_ptr<FontFamily>& matchFallbackFont(
uint32_t ch,
std::string locale) = 0;
virtual const std::shared_ptr<FontFamily>& matchFallbackFontFromHwFont(
uint32_t ch,
std::string locale) = 0;
};
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;
bool hasVariationSelector(uint32_t baseCodepoint,
uint32_t variationSelector) const;
FakedFont baseFontFaked(FontStyle style);
std::shared_ptr<FontCollection> createCollectionWithVariation(
const std::vector<FontVariation>& variations);
const std::unordered_set<AxisTag>& getSupportedTags() const {
return mSupportedAxes;
}
uint32_t getId() const;
void set_fallback_font_provider(std::unique_ptr<FallbackFontProvider> ffp) {
mFallbackFontProvider = std::move(ffp);
}
void SetIsZawgyiMyanmar(bool isZawgyiMyanmar) {
mIsZawgyiMyanmar = isZawgyiMyanmar;
}
private:
static const int kLogCharsPerPage = 8;
static const int kPageMask = (1 << kLogCharsPerPage) - 1;
struct Range {
uint16_t start;
uint16_t end;
};
void init(const std::vector<std::shared_ptr<FontFamily>>& typefaces);
const std::shared_ptr<FontFamily>& getFamilyForChar(uint32_t ch,
uint32_t vs,
uint32_t langListId,
int variant) const;
uint32_t calcFamilyScore(uint32_t ch,
uint32_t vs,
int variant,
uint32_t langListId,
const std::shared_ptr<FontFamily>& fontFamily) const;
uint32_t calcCoverageScore(
uint32_t ch,
uint32_t vs,
const std::shared_ptr<FontFamily>& fontFamily) const;
static uint32_t calcLanguageMatchingScore(uint32_t userLangListId,
const FontFamily& fontFamily);
static uint32_t calcVariantMatchingScore(int variant,
const FontFamily& fontFamily);
static uint32_t sNextId;
uint32_t mId;
uint32_t mMaxChar;
std::vector<std::shared_ptr<FontFamily>> mFamilies;
std::vector<Range> mRanges;
std::vector<uint8_t> mFamilyVec;
std::vector<std::shared_ptr<FontFamily>> mVSFamilyVec;
std::unordered_set<AxisTag> mSupportedAxes;
std::unique_ptr<FallbackFontProvider> mFallbackFontProvider;
bool mIsZawgyiMyanmar = false;
};
}
#endif