2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2020-12-31 14:01:59 +01:00
|
|
|
* Copyright (c) 2020, Stephan Unverwerth <s.unverwerth@gmx.de>
|
2020-01-18 09:38:21 +01:00
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
|
*
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-10-11 23:45:57 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-04-03 13:51:49 +02:00
|
|
|
#include <AK/MappedFile.h>
|
2019-06-21 18:58:45 +02:00
|
|
|
#include <AK/RefCounted.h>
|
2020-02-06 11:56:38 +01:00
|
|
|
#include <AK/RefPtr.h>
|
|
|
|
|
#include <AK/String.h>
|
2018-10-11 23:45:57 +02:00
|
|
|
#include <AK/Types.h>
|
2021-01-02 14:49:20 +01:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2020-02-15 01:03:37 +01:00
|
|
|
#include <LibGfx/Size.h>
|
2020-02-06 11:56:38 +01:00
|
|
|
|
|
|
|
|
namespace Gfx {
|
2018-10-11 23:45:57 +02:00
|
|
|
|
2019-02-05 06:43:33 +01:00
|
|
|
// FIXME: Make a MutableGlyphBitmap buddy class for FontEditor instead?
|
|
|
|
|
class GlyphBitmap {
|
|
|
|
|
public:
|
2021-01-02 14:49:20 +01:00
|
|
|
GlyphBitmap() = default;
|
|
|
|
|
GlyphBitmap(const unsigned* rows, IntSize size)
|
|
|
|
|
: m_rows(rows)
|
|
|
|
|
, m_size(size)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-05 06:43:33 +01:00
|
|
|
const unsigned* rows() const { return m_rows; }
|
|
|
|
|
unsigned row(unsigned index) const { return m_rows[index]; }
|
|
|
|
|
|
|
|
|
|
bool bit_at(int x, int y) const { return row(y) & (1 << x); }
|
|
|
|
|
void set_bit_at(int x, int y, bool b)
|
|
|
|
|
{
|
|
|
|
|
auto& mutable_row = const_cast<unsigned*>(m_rows)[y];
|
|
|
|
|
if (b)
|
|
|
|
|
mutable_row |= 1 << x;
|
|
|
|
|
else
|
|
|
|
|
mutable_row &= ~(1 << x);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-10 10:57:59 +02:00
|
|
|
IntSize size() const { return m_size; }
|
2019-02-05 06:43:33 +01:00
|
|
|
int width() const { return m_size.width(); }
|
|
|
|
|
int height() const { return m_size.height(); }
|
|
|
|
|
|
|
|
|
|
private:
|
2021-01-02 14:49:20 +01:00
|
|
|
const unsigned* m_rows { nullptr };
|
|
|
|
|
IntSize m_size { 0, 0 };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Glyph {
|
|
|
|
|
public:
|
2021-01-03 17:31:18 +01:00
|
|
|
Glyph(const GlyphBitmap& glyph_bitmap, int left_bearing, int advance, int ascent)
|
2021-01-02 14:49:20 +01:00
|
|
|
: m_glyph_bitmap(glyph_bitmap)
|
2021-01-03 17:31:18 +01:00
|
|
|
, m_left_bearing(left_bearing)
|
|
|
|
|
, m_advance(advance)
|
|
|
|
|
, m_ascent(ascent)
|
2019-02-05 06:43:33 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 18:22:22 +01:00
|
|
|
Glyph(RefPtr<Bitmap> bitmap, int left_bearing, int advance, int ascent)
|
2021-01-02 14:49:20 +01:00
|
|
|
: m_bitmap(bitmap)
|
2021-01-02 18:22:22 +01:00
|
|
|
, m_left_bearing(left_bearing)
|
|
|
|
|
, m_advance(advance)
|
|
|
|
|
, m_ascent(ascent)
|
2021-01-02 14:49:20 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_glyph_bitmap() const { return !m_bitmap; }
|
|
|
|
|
GlyphBitmap glyph_bitmap() const { return m_glyph_bitmap; }
|
|
|
|
|
RefPtr<Bitmap> bitmap() const { return m_bitmap; }
|
2021-01-02 18:22:22 +01:00
|
|
|
int left_bearing() const { return m_left_bearing; }
|
|
|
|
|
int advance() const { return m_advance; }
|
|
|
|
|
int ascent() const { return m_ascent; }
|
2021-01-02 14:49:20 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
GlyphBitmap m_glyph_bitmap;
|
|
|
|
|
RefPtr<Bitmap> m_bitmap;
|
2021-01-02 18:22:22 +01:00
|
|
|
int m_left_bearing;
|
|
|
|
|
int m_advance;
|
|
|
|
|
int m_ascent;
|
2019-02-05 06:43:33 +01:00
|
|
|
};
|
|
|
|
|
|
2019-06-21 15:29:31 +02:00
|
|
|
class Font : public RefCounted<Font> {
|
2018-10-11 23:45:57 +02:00
|
|
|
public:
|
2020-12-31 14:01:59 +01:00
|
|
|
virtual NonnullRefPtr<Font> clone() const = 0;
|
|
|
|
|
virtual ~Font() {};
|
2018-10-11 23:45:57 +02:00
|
|
|
|
2020-12-31 14:01:59 +01:00
|
|
|
virtual u8 presentation_size() const = 0;
|
2019-02-03 03:06:58 +01:00
|
|
|
|
2020-12-31 14:01:59 +01:00
|
|
|
virtual u16 weight() const = 0;
|
2021-01-02 14:49:20 +01:00
|
|
|
virtual Glyph glyph(u32 code_point) const = 0;
|
2021-01-03 19:24:59 +01:00
|
|
|
virtual bool contains_glyph(u32 code_point) const = 0;
|
2019-03-06 12:52:41 +01:00
|
|
|
|
2020-12-31 14:01:59 +01:00
|
|
|
virtual u8 glyph_width(size_t ch) const = 0;
|
|
|
|
|
virtual int glyph_or_emoji_width(u32 code_point) const = 0;
|
|
|
|
|
virtual u8 glyph_height() const = 0;
|
|
|
|
|
virtual int x_height() const = 0;
|
2019-12-30 11:36:55 +01:00
|
|
|
|
2020-12-31 14:01:59 +01:00
|
|
|
virtual u8 min_glyph_width() const = 0;
|
|
|
|
|
virtual u8 max_glyph_width() const = 0;
|
|
|
|
|
virtual u8 glyph_fixed_width() const = 0;
|
2019-03-06 11:03:10 +01:00
|
|
|
|
2020-12-31 14:01:59 +01:00
|
|
|
virtual u8 baseline() const = 0;
|
|
|
|
|
virtual u8 mean_line() const = 0;
|
2020-05-08 23:06:33 +03:00
|
|
|
|
2020-12-31 14:01:59 +01:00
|
|
|
virtual int width(const StringView&) const = 0;
|
|
|
|
|
virtual int width(const Utf8View&) const = 0;
|
|
|
|
|
virtual int width(const Utf32View&) const = 0;
|
2019-02-02 23:13:12 +01:00
|
|
|
|
2021-01-02 14:49:20 +01:00
|
|
|
virtual String name() const = 0;
|
2019-04-03 13:51:49 +02:00
|
|
|
|
2020-12-31 14:01:59 +01:00
|
|
|
virtual bool is_fixed_width() const = 0;
|
2020-10-05 16:19:37 +01:00
|
|
|
|
2020-12-31 14:01:59 +01:00
|
|
|
virtual u8 glyph_spacing() const = 0;
|
2018-10-11 23:45:57 +02:00
|
|
|
|
2021-04-18 22:11:41 +03:00
|
|
|
virtual size_t glyph_count() const = 0;
|
2019-02-05 06:43:33 +01:00
|
|
|
|
2021-01-02 14:49:20 +01:00
|
|
|
virtual String family() const = 0;
|
|
|
|
|
virtual String variant() const = 0;
|
2019-03-06 11:03:10 +01:00
|
|
|
|
2020-12-31 14:01:59 +01:00
|
|
|
virtual String qualified_name() const = 0;
|
2020-12-31 01:49:05 +01:00
|
|
|
|
2020-12-31 14:01:59 +01:00
|
|
|
virtual const Font& bold_variant() const = 0;
|
2018-10-11 23:45:57 +02:00
|
|
|
};
|
2020-02-06 11:56:38 +01:00
|
|
|
|
|
|
|
|
}
|