Pull in bitmap related stuff, WIP implementing draw bitmap method
This commit is contained in:
parent
9636baae38
commit
8817e92795
|
@ -180,6 +180,28 @@ static nserror plot_path(const struct redraw_context *ctx, const plot_style_t *p
|
||||||
|
|
||||||
static nserror plot_bitmap(const struct redraw_context *ctx, struct bitmap *bitmap, int x, int y, int width, int height, colour bg, bitmap_flags_t flags) {
|
static nserror plot_bitmap(const struct redraw_context *ctx, struct bitmap *bitmap, int x, int y, int width, int height, colour bg, bitmap_flags_t flags) {
|
||||||
NSLog(@"plot_bitmap");
|
NSLog(@"plot_bitmap");
|
||||||
|
[NSGraphicsContext saveGraphicsState];
|
||||||
|
[NSBezierPath clipRect: cocoa_plot_clip_rect];
|
||||||
|
|
||||||
|
const bool tileX = flags & BITMAPF_REPEAT_X;
|
||||||
|
const bool tileY = flags & BITMAPF_REPEAT_Y;
|
||||||
|
|
||||||
|
NSBitmapImageRep *bmp = (id)bitmap;
|
||||||
|
|
||||||
|
NSRect rect = NSMakeRect(x, y, width, height );
|
||||||
|
|
||||||
|
NSImage *image = [[NSImage alloc] init];
|
||||||
|
[image addRepresentation: bmp];
|
||||||
|
|
||||||
|
NSAffineTransform *tf = [GSCurrentContext() GSCurrentCTM];
|
||||||
|
[tf scaleXBy: 0.85 yBy: 0.85];
|
||||||
|
[GSCurrentContext() GSSetCTM: tf];
|
||||||
|
//[GSCurrentContext() DPSscale: 1.0, y: -1.0];
|
||||||
|
[image drawRepresentation: bmp inRect: rect];
|
||||||
|
[image release];
|
||||||
|
|
||||||
|
[NSGraphicsContext restoreGraphicsState];
|
||||||
|
|
||||||
return NSERROR_OK;
|
return NSERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +210,7 @@ static nserror plot_text(const struct redraw_context *ctx, const plot_font_style
|
||||||
[NSGraphicsContext saveGraphicsState];
|
[NSGraphicsContext saveGraphicsState];
|
||||||
[NSBezierPath clipRect: cocoa_plot_clip_rect];
|
[NSBezierPath clipRect: cocoa_plot_clip_rect];
|
||||||
|
|
||||||
cocoa_draw_string(x, y, text, length, fstyle);
|
//cocoa_draw_string(x, y, text, length, fstyle);
|
||||||
|
|
||||||
[NSGraphicsContext restoreGraphicsState];
|
[NSGraphicsContext restoreGraphicsState];
|
||||||
|
|
||||||
|
@ -230,4 +252,8 @@ static const struct plotter_table gnustep_plotters = {
|
||||||
browser_window_redraw(browser, 0, 0, &clip, &ctx);
|
browser_window_redraw(browser, 0, 0, &clip, &ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(BOOL)isFlipped {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -1,8 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Mostly based on the cocoa port:
|
||||||
|
* Copyright 2011 Sven Weidauer <sven.weidauer@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
||||||
|
*
|
||||||
|
* NetSurf 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; version 2 of the License.
|
||||||
|
*
|
||||||
|
* NetSurf 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
#import "netsurf/netsurf.h"
|
#import "netsurf/netsurf.h"
|
||||||
#import "netsurf/bitmap.h"
|
#import "netsurf/bitmap.h"
|
||||||
|
|
||||||
|
#define BITS_PER_SAMPLE (8)
|
||||||
|
#define SAMPLES_PER_PIXEL (4)
|
||||||
|
#define BITS_PER_PIXEL (BITS_PER_SAMPLE * SAMPLES_PER_PIXEL)
|
||||||
|
#define BYTES_PER_PIXEL (BITS_PER_PIXEL / 8)
|
||||||
|
#define RED_OFFSET (0)
|
||||||
|
#define GREEN_OFFSET (1)
|
||||||
|
#define BLUE_OFFSET (2)
|
||||||
|
#define ALPHA_OFFSET (3)
|
||||||
|
|
||||||
/********************/
|
/********************/
|
||||||
/****** Bitmap ******/
|
/****** Bitmap ******/
|
||||||
|
@ -11,65 +39,99 @@
|
||||||
// Create a new bitmap of width height
|
// Create a new bitmap of width height
|
||||||
static void *gnustep_bitmap_create(int width, int height, unsigned int state) {
|
static void *gnustep_bitmap_create(int width, int height, unsigned int state) {
|
||||||
NSLog(@"gnustep_bitmap_create");
|
NSLog(@"gnustep_bitmap_create");
|
||||||
return NULL;
|
NSBitmapImageRep *bmp = [[NSBitmapImageRep alloc]
|
||||||
|
initWithBitmapDataPlanes: NULL
|
||||||
|
pixelsWide: width
|
||||||
|
pixelsHigh: height
|
||||||
|
bitsPerSample: BITS_PER_SAMPLE
|
||||||
|
samplesPerPixel: SAMPLES_PER_PIXEL
|
||||||
|
hasAlpha: YES
|
||||||
|
isPlanar: NO
|
||||||
|
colorSpaceName: NSDeviceRGBColorSpace
|
||||||
|
bitmapFormat: NSAlphaNonpremultipliedBitmapFormat
|
||||||
|
bytesPerRow: BYTES_PER_PIXEL * width
|
||||||
|
bitsPerPixel: BITS_PER_PIXEL];
|
||||||
|
return (void*) bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy the specified bitmap
|
// Destroy the specified bitmap
|
||||||
static void gnustep_bitmap_destroy(void *bitmap) {
|
static void gnustep_bitmap_destroy(void *bitmap) {
|
||||||
NSLog(@"gnustep_bitmap_destroy");
|
NSLog(@"gnustep_bitmap_destroy");
|
||||||
|
[(id)bitmap dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set whether it's opaque or not
|
// Set whether it's opaque or not
|
||||||
static void gnustep_bitmap_set_opaque(void *bitmap, bool opaque) {
|
static void gnustep_bitmap_set_opaque(void *bitmap, bool opaque) {
|
||||||
NSLog(@"gnustep_bitmap_set_opaque");
|
NSLog(@"gnustep_bitmap_set_opaque");
|
||||||
|
if (opaque) {
|
||||||
|
[(id)bitmap setOpaque: YES];
|
||||||
|
} else {
|
||||||
|
[(id)bitmap setOpaque: NO];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get whether it's opaque or not
|
// Get whether it's opaque or not
|
||||||
static bool gnustep_bitmap_get_opaque(void *bitmap) {
|
static bool gnustep_bitmap_get_opaque(void *bitmap) {
|
||||||
NSLog(@"gnustep_bitmap_get_opaque");
|
NSLog(@"gnustep_bitmap_get_opaque");
|
||||||
return 0;
|
return [(id)bitmap isOpaque];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test? whether it's opaque or not
|
// Test? whether it's opaque or not
|
||||||
static bool gnustep_bitmap_test_opaque(void *bitmap) {
|
static bool gnustep_bitmap_test_opaque(void *bitmap) {
|
||||||
NSLog(@"gnustep_bitmap_test_opaque");
|
NSLog(@"gnustep_bitmap_test_opaque");
|
||||||
return 0;
|
unsigned char *buf = [(id)bitmap bitmapData];
|
||||||
|
|
||||||
|
const size_t height = [(id)bitmap pixelsHigh];
|
||||||
|
const size_t width = [(id)bitmap pixelsWide];
|
||||||
|
|
||||||
|
const size_t line_step = [(id)bitmap bytesPerRow] - BYTES_PER_PIXEL * width;
|
||||||
|
|
||||||
|
for (size_t y = 0; y < height; y++) {
|
||||||
|
for (size_t x = 0; x < height; x++) {
|
||||||
|
if (buf[ALPHA_OFFSET] != 0xFF) return false;
|
||||||
|
buf += BYTES_PER_PIXEL;
|
||||||
|
}
|
||||||
|
buf += line_step;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the image buffer for the bitmap
|
// Get the image buffer for the bitmap
|
||||||
static unsigned char *gnustep_bitmap_get_buffer(void *bitmap) {
|
static unsigned char *gnustep_bitmap_get_buffer(void *bitmap) {
|
||||||
NSLog(@"gnustep_bitmap_get_buffer");
|
NSLog(@"gnustep_bitmap_get_buffer");
|
||||||
return NULL;
|
return [(id)bitmap bitmapData];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the number of bytes per row of the bitmap
|
// Get the number of bytes per row of the bitmap
|
||||||
static size_t gnustep_bitmap_get_rowstride(void *bitmap) {
|
static size_t gnustep_bitmap_get_rowstride(void *bitmap) {
|
||||||
NSLog(@"gnustep_bitmap_get_rowstride");
|
NSLog(@"gnustep_bitmap_get_rowstride");
|
||||||
return 0;
|
return [(id)bitmap bytesPerRow];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get its width in pixels
|
// Get its width in pixels
|
||||||
static int gnustep_bitmap_get_width(void *bitmap) {
|
static int gnustep_bitmap_get_width(void *bitmap) {
|
||||||
NSLog(@"gnustep_bitmap_get_width");
|
NSLog(@"gnustep_bitmap_get_width");
|
||||||
return 0;
|
return [(id)bitmap pixelsWide];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get height in pixels
|
// Get height in pixels
|
||||||
static int gnustep_bitmap_get_height(void *bitmap) {
|
static int gnustep_bitmap_get_height(void *bitmap) {
|
||||||
NSLog(@"gnustep_bitmap_get_height");
|
NSLog(@"gnustep_bitmap_get_height");
|
||||||
return 0;
|
return [(id)bitmap pixelsHigh];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get how many byytes pet pixel
|
// Get how many byytes pet pixel
|
||||||
static size_t gnustep_bitmap_get_bpp(void *bitmap) {
|
static size_t gnustep_bitmap_get_bpp(void *bitmap) {
|
||||||
NSLog(@"gnustep_bitmap_get_bpp");
|
NSLog(@"gnustep_bitmap_get_bpp");
|
||||||
return 0;
|
return [(id)bitmap bitsPerPixel] / 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the bitmap to the specified path
|
// Save the bitmap to the specified path
|
||||||
static bool gnustep_bitmap_save(void *bitmap, const char *path, unsigned flags) {
|
static bool gnustep_bitmap_save(void *bitmap, const char *path, unsigned flags) {
|
||||||
NSLog(@"gnustep_bitmap_save");
|
NSLog(@"gnustep_bitmap_save");
|
||||||
return 0;
|
NSData *tiff = [(id)bitmap TIFFRepresentation];
|
||||||
|
return [tiff writeToFile: [NSString stringWithUTF8String: path] atomically: YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark bitmap as modified
|
// Mark bitmap as modified
|
||||||
|
|
|
@ -151,8 +151,9 @@ static inline CGFloat cocoa_layout_width( NSLayoutManager *layout )
|
||||||
|
|
||||||
static inline CGFloat cocoa_layout_width_chars( NSLayoutManager *layout, size_t characters )
|
static inline CGFloat cocoa_layout_width_chars( NSLayoutManager *layout, size_t characters )
|
||||||
{
|
{
|
||||||
NSUInteger glyphIndex = [layout glyphIndexForCharacterAtIndex: characters];
|
NSRange range = [layout glyphRangeForCharacterRange:
|
||||||
return [layout locationForGlyphAtIndex: glyphIndex].x;
|
NSMakeRange((unsigned int)characters, 1) actualCharacterRange: NULL];
|
||||||
|
return [layout locationForGlyphAtIndex: range.location].x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline NSUInteger cocoa_glyph_for_location( NSLayoutManager *layout, CGFloat x )
|
static inline NSUInteger cocoa_glyph_for_location( NSLayoutManager *layout, CGFloat x )
|
||||||
|
|
Loading…
Reference in New Issue