all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob abb47220e92a35befdae3d7b69e41e520a43d3b6 3649 bytes (raw)
name: src/haiku_freetype.cc 	 # 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
 
/* 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 "haiku_support.h"

#include <View.h>
#include <Bitmap.h>
#include <Point.h>
#include <Region.h>

#include <alloca.h>
#include <cstddef>
#include <cmath>
#include <algorithm>

#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_SIZES_H
#include FT_BITMAP_H

#define ARGB_TO_ULONG(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
#define RED_FROM_ULONG(color)	(((color) >> 16) & 0xff)
#define GREEN_FROM_ULONG(color)	(((color) >> 8) & 0xff)
#define BLUE_FROM_ULONG(color)	((color) & 0xff)

extern "C"
{
  extern void emacs_abort (void);
}

static void
render_g8 (FT_Bitmap *bitmap, uint32_t color, int dx, int dy, BBitmap *bm,
	   int max_x, int max_y, BRegion *region)
{
  if (!bitmap->width || !bitmap->rows)
    return;

  for (int y = 0; y < bitmap->rows; ++y)
    {
      if (y + dy >= max_y)
	continue;

      uint8_t *row_start_glyph =
	(uint8_t *) &bitmap->buffer[y * bitmap->pitch];
      uint32_t *row_start_bitmap = ((uint32_t *) bm->Bits ()) +
	(y + dy) * bm->BytesPerRow () / 4;

      for (int x = 0; x < bitmap->width; ++x)
	{
	  if (x + dx > max_x || region->Contains (x, y))
	    continue;

	  int existing = (int) (row_start_bitmap[x + dx] >> 24);

	  row_start_bitmap[x + dx] =
	    ARGB_TO_ULONG (std::min (255, existing +
				     (int) std::lrint ((double) row_start_glyph[x] /
						       (double) bitmap->num_grays * 255)),
			   RED_FROM_ULONG (color),
			   GREEN_FROM_ULONG (color),
			   BLUE_FROM_ULONG (color));
	}
    }
}

extern void
BView_FT_render_glyphs (FT_Face face, unsigned int *codes,
			int len, uint32_t color, int x, int y,
			void *view, int width, int height,
			int sx, int sy)
{
  FT_Error error = FT_Err_Ok;
  BView *vw = (BView *) view;
  static BBitmap *canvas = NULL;
  BRegion reg;

  int view_width, view_height;
  view_width = vw->Bounds ().Width ();
  view_height = vw->Bounds ().Height ();

  vw->GetClippingRegion (&reg);

  if (canvas && (canvas->Bounds () != vw->Bounds ()))
    {
      delete canvas;
      canvas = NULL;
    }

  if (!canvas)
    canvas = new BBitmap (vw->Bounds (), B_RGBA32);

  if (!canvas->InitCheck ())
    emacs_abort ();

  memset (canvas->Bits (), 0, canvas->BitsLength ());

  for (int i = 0; i < len; ++i)
    {
      error = FT_Load_Glyph (face, codes[i], FT_LOAD_DEFAULT);

      if (error != FT_Err_Ok)
	continue;

      if (face->glyph->format != FT_GLYPH_FORMAT_BITMAP)
	{
	  error = FT_Render_Glyph (face->glyph, FT_RENDER_MODE_NORMAL);
	  if (error)
	    {
	      x += face->glyph->advance.x >> 6;
	      y += face->glyph->advance.y >> 6;
	      continue;
	    }

	  render_g8 (&face->glyph->bitmap, color,
		     x + face->glyph->bitmap_left,
		     y - face->glyph->bitmap_top,
		     canvas, view_width, view_height, &reg);
	}
      x += face->glyph->advance.x >> 6;
      y += face->glyph->advance.y >> 6;
    }

  vw->SetDrawingMode (B_OP_OVER);
  vw->DrawBitmap (canvas);
}

debug log:

solving abb47220e9 ...
found abb47220e9 in https://yhetil.org/emacs/87zgssfuz9.fsf@yahoo.com/

applying [1/1] https://yhetil.org/emacs/87zgssfuz9.fsf@yahoo.com/
diff --git a/src/haiku_freetype.cc b/src/haiku_freetype.cc
new file mode 100644
index 0000000000..abb47220e9

Checking patch src/haiku_freetype.cc...
Applied patch src/haiku_freetype.cc cleanly.

index at:
100644 abb47220e92a35befdae3d7b69e41e520a43d3b6	src/haiku_freetype.cc

(*) 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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.