unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 80f7a3a34cba2220bb6242c7575a21d7ee11472a 7177 bytes (raw)
name: src/ftbefont.c 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
 
/* FreeType font driver for Haiku
   Copyright (C) 2021 Free Software Foundation, Inc.

This file is part of GNU Emacs.

GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */

#include <config.h>

#include "blockinput.h"
#include "haiku_support.h"
#include "lisp.h"
#include "dispextern.h"
#include "font.h"
#include "pdumper.h"
#include "frame.h"
#include "haikuterm.h"
#include "termchar.h"
#include "math.h"
#include "ftfont.h"

#ifdef HAVE_HARFBUZZ
#include <hb.h>
#include <hb-ft.h>
#endif

static Lisp_Object
ftbefont_list (struct frame *f, Lisp_Object spec)
{
  return ftfont_list2 (f, spec, Qftbe);
}

static Lisp_Object
ftbefont_match (struct frame *f, Lisp_Object spec)
{
  return ftfont_match2 (f, spec, Qftbe);
}

#ifdef HAVE_HARFBUZZ

static Lisp_Object
ftbehbfont_list (struct frame *f, Lisp_Object spec)
{
  return ftfont_list2 (f, spec, Qftbehb);
}

static Lisp_Object
ftbehbfont_match (struct frame *f, Lisp_Object spec)
{
  return ftfont_match2 (f, spec, Qftbehb);
}

#endif

static int
ftbefont_draw (struct glyph_string *s,
               int from, int to, int x, int y, bool with_background)
{
  struct frame *f = s->f;
  struct face *face = s->face;
  struct font_info *info = (struct font_info *) s->font;
  void *view = FRAME_HAIKU_VIEW (f);

  block_input ();
  prepare_face_for_display (s->f, face);

  if (info->ft_size != info->face->size)
    FT_Activate_Size (info->ft_size);

  BView_draw_lock (view);
  BView_StartClip (view);

  if (with_background)
    {
      int height = FONT_HEIGHT (s->font), ascent = FONT_BASE (s->font);

      /* Font's global height and ascent values might be
	 preposterously large for some fonts.  We fix here the case
	 when those fonts are used for display of glyphless
	 characters, because drawing background with font dimensions
	 in those cases makes the display illegible.  There's only one
	 more call to the draw method with with_background set to
	 true, and that's in x_draw_glyph_string_foreground, when
	 drawing the cursor, where we have no such heuristics
	 available.  FIXME.  */
      if (s->first_glyph->type == GLYPHLESS_GLYPH
	  && (s->first_glyph->u.glyphless.method == GLYPHLESS_DISPLAY_HEX_CODE
	      || s->first_glyph->u.glyphless.method == GLYPHLESS_DISPLAY_ACRONYM))
	height = ascent =
	  s->first_glyph->slice.glyphless.lower_yoff
	  - s->first_glyph->slice.glyphless.upper_yoff;

      BView_SetHighColor (view, s->hl == DRAW_CURSOR ?
			  FRAME_CURSOR_COLOR (s->f).pixel : face->background);

      BView_FillRectangle (view, x, y - ascent, s->width, height);
      s->background_filled_p = 1;
    }

  if (s->left_overhang && s->clip_head && !s->for_overlaps)
    {
      /* XXX: Why is this neccessary? */
      BView_ClipToRect (view, s->clip_head->x, 0,
			FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f));
    }

  if (s->hl == DRAW_CURSOR)
    BView_FT_render_glyphs (info->face, &s->char2b[from], to - from,
			    FRAME_OUTPUT_DATA (s->f)->cursor_fg, x, y, view,
			    info->sc, FT_LOAD_DEFAULT);
  else
    BView_FT_render_glyphs (info->face, &s->char2b[from], to - from,
			    face->foreground, x, y, view, info->sc,
			    FT_LOAD_DEFAULT);

  BView_EndClip (view);
  BView_draw_unlock (view);
  unblock_input ();
  return 0;
}

static Lisp_Object
ftbefont_open (struct frame *f, Lisp_Object entity, int pixel_size)
{
  Lisp_Object ft = ftfont_open (f, entity, pixel_size);
  if (FONT_OBJECT_P (ft))
    {
      struct font_info *info = (struct font_info *) XFONT_OBJECT (ft);
      ASET (ft, FONT_TYPE_INDEX, Qftbe);
      info->font.driver = &ftbefont_driver;
      info->sc = be_make_ft_shape_cache ();
    }
  return ft;
}

#ifdef HAVE_HARFBUZZ
static hb_font_t *
ftbehbfont_begin_hb_font (struct font *font, double *position_unit)
{
  struct font_info *ftfont_info = (struct font_info *) font;
  FT_Face ft_face = ftfont_info->face;

  ftfont_info->ft_size = ft_face->size;
  return fthbfont_begin_hb_font (font, position_unit);
}

static void
ftbehbfont_end_hb_font (struct font *font, hb_font_t *hb_font)
{
  struct font_info *ftfont_info = (struct font_info *) font;
  ftfont_info->ft_size = NULL;
}

static Lisp_Object
ftbehbfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
{
  Lisp_Object ft = ftfont_open (f, entity, pixel_size);
  if (FONT_OBJECT_P (ft))
    {
      struct font_info *info = (struct font_info *) XFONT_OBJECT (ft);
      ASET (ft, FONT_TYPE_INDEX, Qftbehb);
      info->font.driver = &ftbehbfont_driver;
      info->sc = be_make_ft_shape_cache ();
    }
  return ft;
}
#endif

static void
ftbefont_close (struct font *font)
{
  if (font_data_structures_may_be_ill_formed ())
    return;
  be_free_ft_shape_cache (((struct font_info *) font)->sc);
  ftfont_close (font);
}

struct font_driver const ftbefont_driver =
  {
    .type = LISPSYM_INITIALLY (Qftbe),
    .get_cache = ftfont_get_cache,
    .list = ftbefont_list,
    .match = ftbefont_match,
    .draw = ftbefont_draw,
    .list_family = ftfont_list_family,
    .open_font = ftbefont_open,
    .close_font = ftbefont_close,
    .has_char = ftfont_has_char,
    .encode_char = ftfont_encode_char,
    .text_extents = ftfont_text_extents,
    .get_bitmap = ftfont_get_bitmap,
    .anchor_point = ftfont_anchor_point,
#ifdef HAVE_LIBOTF
    .otf_capability = ftfont_otf_capability,
#endif
#if defined HAVE_M17N_FLT && defined HAVE_LIBOTF
    .shape = ftfont_shape,
#endif
#if defined HAVE_OTF_GET_VARIATION_GLYPHS || defined HAVE_FT_FACE_GETCHARVARIANTINDEX
    .get_variation_glyphs = ftfont_variation_glyphs,
#endif
    .filter_properties = ftfont_filter_properties,
    .combining_capability = ftfont_combining_capability
  };

#ifdef HAVE_HARFBUZZ
struct font_driver ftbehbfont_driver;
#endif

static void
syms_of_ftbefont_for_pdumper (void)
{
  register_font_driver (&ftbefont_driver, NULL);
#ifdef HAVE_HARFBUZZ
  ftbehbfont_driver = ftbefont_driver;
  ftbehbfont_driver.type = Qftbehb;
  ftbehbfont_driver.list = ftbehbfont_list;
  ftbehbfont_driver.match = ftbehbfont_match;
  ftbehbfont_driver.otf_capability = hbfont_otf_capability;
  ftbehbfont_driver.shape = hbfont_shape;
  ftbehbfont_driver.open_font = ftbehbfont_open;
  ftbehbfont_driver.combining_capability = hbfont_combining_capability;
  ftbehbfont_driver.begin_hb_font = ftbehbfont_begin_hb_font;
  ftbehbfont_driver.end_hb_font = ftbehbfont_end_hb_font;

  register_font_driver (&ftbehbfont_driver, NULL);
#endif
}

void
syms_of_ftbefont (void)
{
  DEFSYM (Qftbe, "ftbe");
#ifdef HAVE_HARFBUZZ
  DEFSYM (Qftbehb, "ftbehb");
  Fput (Qftbe, Qfont_driver_superseded_by, Qftbehb);
#endif
  pdumper_do_now_and_after_load (syms_of_ftbefont_for_pdumper);
}

debug log:

solving 80f7a3a34c ...
found 80f7a3a34c in https://yhetil.org/emacs-bugs/87ee7surtv.fsf@yahoo.com/

applying [1/1] https://yhetil.org/emacs-bugs/87ee7surtv.fsf@yahoo.com/
diff --git a/src/ftbefont.c b/src/ftbefont.c
new file mode 100644
index 0000000000..80f7a3a34c

Checking patch src/ftbefont.c...
Applied patch src/ftbefont.c cleanly.

index at:
100644 80f7a3a34cba2220bb6242c7575a21d7ee11472a	src/ftbefont.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).