Add font support
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "Definitions.h"
|
||||
#include "Extensions.h"
|
||||
#include "Font.h"
|
||||
#include "Image.h"
|
||||
#include "Keymap.h"
|
||||
#include "Utils.h"
|
||||
@@ -2375,26 +2376,17 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
||||
break;
|
||||
}
|
||||
case X_OpenFont:
|
||||
{
|
||||
auto request = decode<xOpenFontReq>(packet).value();
|
||||
|
||||
auto name = BAN::StringView((char*)packet.data(), request.nbytes);
|
||||
dwarnln("OpenFont");
|
||||
dwarnln(" fid: {}", request.fid);
|
||||
dwarnln(" name: {}", name);
|
||||
|
||||
xError error {
|
||||
.type = X_Error,
|
||||
.errorCode = BadName,
|
||||
.sequenceNumber = client_info.sequence,
|
||||
.resourceID = 0,
|
||||
.minorCode = 0,
|
||||
.majorCode = opcode,
|
||||
};
|
||||
TRY(encode(client_info.output_buffer, error));
|
||||
|
||||
TRY(open_font(client_info, packet));
|
||||
break;
|
||||
case X_CloseFont:
|
||||
TRY(close_font(client_info, packet));
|
||||
break;
|
||||
case X_QueryFont:
|
||||
TRY(query_font(client_info, packet));
|
||||
break;
|
||||
case X_ListFonts:
|
||||
TRY(list_fonts(client_info, packet));
|
||||
break;
|
||||
}
|
||||
case X_GetInputFocus:
|
||||
{
|
||||
dprintln("GetInputFocus");
|
||||
@@ -2473,6 +2465,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
||||
|
||||
uint32_t foreground = 0x000000;
|
||||
uint32_t background = 0x000000;
|
||||
uint32_t font = None;
|
||||
uint32_t clip_mask = 0;
|
||||
int32_t clip_origin_x = 0;
|
||||
int32_t clip_origin_y = 0;
|
||||
@@ -2492,6 +2485,10 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
||||
dprintln(" background: {8h}", value);
|
||||
background = value;
|
||||
break;
|
||||
case 14:
|
||||
dprintln(" font: {}", value);
|
||||
font = value;
|
||||
break;
|
||||
case 17:
|
||||
dprintln(" clip-origin-x: {}", value);
|
||||
clip_origin_x = value;
|
||||
@@ -2516,6 +2513,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
||||
.object = Object::GraphicsContext {
|
||||
.foreground = foreground,
|
||||
.background = background,
|
||||
.font = font,
|
||||
.clip_mask = clip_mask,
|
||||
.clip_origin_x = clip_origin_x,
|
||||
.clip_origin_y = clip_origin_y,
|
||||
@@ -2555,6 +2553,10 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
||||
dprintln(" background: {8h}", value);
|
||||
gc.background = value;
|
||||
break;
|
||||
case 14:
|
||||
dprintln(" font: {}", value);
|
||||
gc.font = value;
|
||||
break;
|
||||
case 17:
|
||||
dprintln(" clip-origin-x: {}", value);
|
||||
gc.clip_origin_x = value;
|
||||
@@ -2988,6 +2990,18 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
||||
|
||||
break;
|
||||
}
|
||||
case X_PolyText8:
|
||||
TRY(poly_text(client_info, packet, false));
|
||||
break;
|
||||
case X_PolyText16:
|
||||
TRY(poly_text(client_info, packet, true));
|
||||
break;
|
||||
case X_ImageText8:
|
||||
TRY(image_text(client_info, packet, false));
|
||||
break;
|
||||
case X_ImageText16:
|
||||
TRY(image_text(client_info, packet, true));
|
||||
break;
|
||||
case X_CreateColormap:
|
||||
{
|
||||
auto request = decode<xCreateColormapReq>(packet).value();
|
||||
@@ -3166,6 +3180,9 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
|
||||
|
||||
break;
|
||||
}
|
||||
case X_CreateGlyphCursor:
|
||||
TRY(create_glyph_cursor(client_info, packet));
|
||||
break;
|
||||
case X_FreeCursor:
|
||||
{
|
||||
const auto cid = packet.as_span<const uint32_t>()[1];
|
||||
|
||||
@@ -4,6 +4,7 @@ set(SOURCES
|
||||
Extensions.cpp
|
||||
ExtBigReg.cpp
|
||||
ExtRANDR.cpp
|
||||
Font.cpp
|
||||
Image.cpp
|
||||
Keymap.cpp
|
||||
)
|
||||
@@ -19,6 +20,7 @@ endif()
|
||||
add_executable(xbanan ${SOURCES})
|
||||
banan_link_library(xbanan ban)
|
||||
banan_link_library(xbanan libgui)
|
||||
banan_link_library(xbanan libdeflate)
|
||||
|
||||
target_compile_options(xbanan PRIVATE -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers)
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Font.h"
|
||||
|
||||
#include <BAN/Vector.h>
|
||||
#include <BAN/UniqPtr.h>
|
||||
#include <BAN/HashMap.h>
|
||||
@@ -41,6 +43,7 @@ struct Object
|
||||
Window,
|
||||
Pixmap,
|
||||
GraphicsContext,
|
||||
Font,
|
||||
Extension,
|
||||
};
|
||||
|
||||
@@ -109,6 +112,8 @@ struct Object
|
||||
uint32_t foreground;
|
||||
uint32_t background;
|
||||
|
||||
uint32_t font;
|
||||
|
||||
uint32_t clip_mask;
|
||||
int32_t clip_origin_x;
|
||||
int32_t clip_origin_y;
|
||||
@@ -142,7 +147,7 @@ struct Object
|
||||
void (*destructor)(Extension&);
|
||||
};
|
||||
|
||||
BAN::Variant<Cursor, Window, Pixmap, GraphicsContext, Extension> object;
|
||||
BAN::Variant<Cursor, Window, Pixmap, GraphicsContext, BAN::RefPtr<PCFFont>, Extension> object;
|
||||
};
|
||||
|
||||
struct Client
|
||||
|
||||
1024
xbanan/Font.cpp
Normal file
1024
xbanan/Font.cpp
Normal file
File diff suppressed because it is too large
Load Diff
70
xbanan/Font.h
Normal file
70
xbanan/Font.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include <BAN/ByteSpan.h>
|
||||
#include <BAN/Optional.h>
|
||||
#include <BAN/Vector.h>
|
||||
#include <BAN/WeakPtr.h>
|
||||
|
||||
#include <X11/Xproto.h>
|
||||
|
||||
struct PCFFont : public BAN::RefCounted<PCFFont>, public BAN::Weakable<PCFFont>
|
||||
{
|
||||
struct Glyph
|
||||
{
|
||||
xCharInfo char_info;
|
||||
uint32_t bitmap_offset;
|
||||
};
|
||||
|
||||
struct MapEntry
|
||||
{
|
||||
uint16_t codepoint;
|
||||
uint16_t glyph_index;
|
||||
};
|
||||
|
||||
uint16_t min_char_or_byte2;
|
||||
uint16_t max_char_or_byte2;
|
||||
uint8_t min_byte1;
|
||||
uint8_t max_byte1;
|
||||
bool all_chars_exist;
|
||||
uint16_t default_char;
|
||||
|
||||
xCharInfo min_bounds;
|
||||
xCharInfo max_bounds;
|
||||
|
||||
int16_t font_ascent;
|
||||
int16_t font_descent;
|
||||
|
||||
// TODO: parse properties
|
||||
|
||||
BAN::Vector<Glyph> glyphs;
|
||||
BAN::Vector<MapEntry> map;
|
||||
BAN::Vector<uint8_t> bitmap;
|
||||
|
||||
BAN::Optional<uint16_t> find_glyph(uint16_t codepoint) const
|
||||
{
|
||||
size_t l = 0;
|
||||
size_t r = map.size();
|
||||
while (l < r)
|
||||
{
|
||||
const size_t mid = (l + r) / 2;
|
||||
|
||||
if (map[mid].codepoint == codepoint)
|
||||
return map[mid].glyph_index;
|
||||
|
||||
if (map[mid].codepoint < codepoint)
|
||||
l = mid + 1;
|
||||
else
|
||||
r = mid;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
struct Client;
|
||||
BAN::ErrorOr<void> open_font(Client& client_info, BAN::ConstByteSpan packet);
|
||||
BAN::ErrorOr<void> close_font(Client& client_info, BAN::ConstByteSpan packet);
|
||||
BAN::ErrorOr<void> query_font(Client& client_info, BAN::ConstByteSpan packet);
|
||||
BAN::ErrorOr<void> list_fonts(Client& client_info, BAN::ConstByteSpan packet);
|
||||
BAN::ErrorOr<void> poly_text(Client& client_info, BAN::ConstByteSpan packet, bool wide);
|
||||
BAN::ErrorOr<void> image_text(Client& client_info, BAN::ConstByteSpan packet, bool wide);
|
||||
BAN::ErrorOr<void> create_glyph_cursor(Client& client_info, BAN::ConstByteSpan packet);
|
||||
Reference in New Issue
Block a user