mirror of
https://github.com/gnustep/libs-back.git
synced 2025-04-22 15:31:14 +00:00
Color and font_cacher fixes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@13636 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
84f42ecd8f
commit
b4e87e4f03
6 changed files with 156 additions and 40 deletions
20
ChangeLog
20
ChangeLog
|
@ -1,3 +1,23 @@
|
|||
2002-05-12 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Source/gsc/GSGState.m (-DPSsetalpha:): Call setColor:state:.
|
||||
Clamp value to 0<x<1
|
||||
(-DPSsetcmykcolor::::): Idem.
|
||||
(-DPSsetgray:):Idem.
|
||||
(-DPSsethsbcolor:::):Idem.
|
||||
(-DPSsetrgbcolor:::):Idem.
|
||||
(-GSSetFontSize:): Use given size.
|
||||
* Source/gsc/gscolors.c (gsHSBToRGB): Fix for h==1.
|
||||
(gsColorToCMYK): Implement.
|
||||
(gsColorToHSB): Idem. (Patches from alexander@malmberg.org).
|
||||
|
||||
* Source/xlib/XGFontManager.m (load_cache): Use NSBundle to find
|
||||
font_cacher.
|
||||
|
||||
* Source/xlib/XGGState.m (GSSetFont:) Rename from setFont.
|
||||
|
||||
* Tools/GNUmakefile: Build font_cacher if BUILD_GRAPHICS=xlib
|
||||
|
||||
2002-05-11 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/Source/xlib/XGFont.m: ([-xCharStructForGlyph:]) use newer
|
||||
|
|
|
@ -236,32 +236,46 @@
|
|||
*r = gcolor.field[0]; *g = gcolor.field[1]; *b = gcolor.field[2];
|
||||
}
|
||||
|
||||
#define CLAMP(x) \
|
||||
if (x < 0.0) x = 0.0; \
|
||||
if (x > 1.0) x = 1.0;
|
||||
|
||||
- (void) DPSsetalpha: (float)a
|
||||
{
|
||||
CLAMP(a)
|
||||
fillColor.field[AINDEX] = strokeColor.field[AINDEX] = a;
|
||||
/* Is this necessary?
|
||||
[self setColor: fillColor state: COLOR_FILL];
|
||||
[self setColor: strokeColor state: COLOR_STROKE];
|
||||
*/
|
||||
}
|
||||
|
||||
- (void) DPSsetcmykcolor: (float)c : (float)m : (float)y : (float)k
|
||||
{
|
||||
CLAMP(c)
|
||||
CLAMP(m)
|
||||
CLAMP(y)
|
||||
CLAMP(k)
|
||||
[self setColor: gsMakeColor(cmyk_colorspace, c, m, y, k) state: COLOR_BOTH];
|
||||
}
|
||||
|
||||
- (void) DPSsetgray: (float)gray
|
||||
{
|
||||
CLAMP(gray)
|
||||
[self setColor: gsMakeColor(gray_colorspace, gray, 0, 0, 0) state: COLOR_BOTH];
|
||||
}
|
||||
|
||||
- (void) DPSsethsbcolor: (float)h : (float)s : (float)b
|
||||
{
|
||||
CLAMP(h)
|
||||
CLAMP(s)
|
||||
CLAMP(b)
|
||||
[self setColor: gsMakeColor(hsb_colorspace, h, s, b, 0) state: COLOR_BOTH];
|
||||
}
|
||||
|
||||
- (void) DPSsetrgbcolor: (float)r : (float)g : (float)b
|
||||
{
|
||||
CLAMP(r)
|
||||
CLAMP(g)
|
||||
CLAMP(b)
|
||||
[self setColor: gsMakeColor(rgb_colorspace, r, g, b, 0) state: COLOR_BOTH];
|
||||
}
|
||||
|
||||
|
@ -397,7 +411,7 @@
|
|||
NSFont *newFont;
|
||||
if (font == nil)
|
||||
return;
|
||||
newFont = [NSFont fontWithName: [font fontName] size: [font pointSize]];
|
||||
newFont = [NSFont fontWithName: [font fontName] size: size];
|
||||
[self GSSetFont: newFont];
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ gsHSBToRGB(device_color_t color)
|
|||
|
||||
switch (i)
|
||||
{
|
||||
default: /* catch h==1.0 */
|
||||
case 0:
|
||||
red = v;
|
||||
green = t;
|
||||
|
@ -118,7 +119,7 @@ gsCMYKToRGB(device_color_t color)
|
|||
y = color.field[2];
|
||||
k = color.field[3];
|
||||
white = 1 - k;
|
||||
|
||||
|
||||
if (k == 0)
|
||||
{
|
||||
red = 1 - c;
|
||||
|
@ -190,7 +191,6 @@ gsColorToGray(device_color_t color)
|
|||
return new;
|
||||
}
|
||||
|
||||
/* FIXME: Not implemented */
|
||||
device_color_t
|
||||
gsColorToCMYK(device_color_t color)
|
||||
{
|
||||
|
@ -200,10 +200,46 @@ gsColorToCMYK(device_color_t color)
|
|||
switch(color.space)
|
||||
{
|
||||
case gray_colorspace:
|
||||
break;
|
||||
case rgb_colorspace:
|
||||
new.field[0] = 0.0;
|
||||
new.field[1] = 0.0;
|
||||
new.field[2] = 0.0;
|
||||
new.field[3] = color.field[0];
|
||||
break;
|
||||
case hsb_colorspace:
|
||||
color = gsColorToRGB(color);
|
||||
/* NO BREAK */
|
||||
case rgb_colorspace:
|
||||
new.field[0] = 1.0 - color.field[0];
|
||||
new.field[1] = 1.0 - color.field[1];
|
||||
new.field[2] = 1.0 - color.field[2];
|
||||
new.field[3] = 0;
|
||||
|
||||
/* Add a bit of black if possible (for no reason, really). */
|
||||
new.field[3] = new.field[0];
|
||||
new.field[0] = 0.0;
|
||||
new.field[1] -= new.field[3];
|
||||
new.field[2] -= new.field[3];
|
||||
if (new.field[1] > new.field[2])
|
||||
{
|
||||
if (new.field[2] < 0.0)
|
||||
{
|
||||
new.field[0] -= new.field[2];
|
||||
new.field[1] -= new.field[2];
|
||||
new.field[3] += new.field[2];
|
||||
new.field[2] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (new.field[1] < 0.0)
|
||||
{
|
||||
new.field[0] -= new.field[1];
|
||||
new.field[2] -= new.field[1];
|
||||
new.field[3] += new.field[1];
|
||||
new.field[1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case cmyk_colorspace:
|
||||
new = color;
|
||||
|
@ -214,7 +250,6 @@ gsColorToCMYK(device_color_t color)
|
|||
return new;
|
||||
}
|
||||
|
||||
/* FIXME: Not implemented */
|
||||
device_color_t
|
||||
gsColorToHSB(device_color_t color)
|
||||
{
|
||||
|
@ -224,13 +259,65 @@ gsColorToHSB(device_color_t color)
|
|||
switch(color.space)
|
||||
{
|
||||
case gray_colorspace:
|
||||
new.field[0] = 0.0;
|
||||
new.field[1] = 0.0;
|
||||
new.field[2] = color.field[0];
|
||||
break;
|
||||
case cmyk_colorspace:
|
||||
color = gsColorToRGB(color);
|
||||
/* NO BREAK */
|
||||
case rgb_colorspace:
|
||||
{
|
||||
float r = color.field[0];
|
||||
float g = color.field[1];
|
||||
float b = color.field[2];
|
||||
float _hue_component, _saturation_component, _brightness_component;
|
||||
|
||||
if (r == g && r == b)
|
||||
{
|
||||
_hue_component = 0;
|
||||
_saturation_component = 0;
|
||||
_brightness_component = r;
|
||||
}
|
||||
else
|
||||
{
|
||||
double H;
|
||||
double V;
|
||||
double Temp;
|
||||
double diff;
|
||||
|
||||
V = (r > g ? r : g);
|
||||
V = (b > V ? b : V);
|
||||
Temp = (r < g ? r : g);
|
||||
Temp = (b < Temp ? b : Temp);
|
||||
diff = V - Temp;
|
||||
if (V == r)
|
||||
{
|
||||
H = (g - b)/diff;
|
||||
}
|
||||
else if (V == g)
|
||||
{
|
||||
H = (b - r)/diff + 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
H = (r - g)/diff + 4;
|
||||
}
|
||||
if (H < 0)
|
||||
{
|
||||
H += 6;
|
||||
}
|
||||
_hue_component = H/6;
|
||||
_saturation_component = diff/V;
|
||||
_brightness_component = V;
|
||||
}
|
||||
new.field[0] = _hue_component;
|
||||
new.field[1] = _saturation_component;
|
||||
new.field[2] = _brightness_component;
|
||||
}
|
||||
break;
|
||||
case hsb_colorspace:
|
||||
new = color;
|
||||
break;
|
||||
case cmyk_colorspace:
|
||||
new = color = gsColorToRGB(color);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include <AppKit/GSFontInfo.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSBundle.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSPathUtilities.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
|
@ -139,7 +140,6 @@ load_cache(NSString *cacheName, BOOL async)
|
|||
|| ([v intValue] != 2))
|
||||
{
|
||||
NSString *file_name = [cacheName lastPathComponent];
|
||||
NSDictionary *env = [[NSProcessInfo processInfo] environment];
|
||||
NSString *path;
|
||||
NSTask *task;
|
||||
|
||||
|
@ -149,13 +149,13 @@ load_cache(NSString *cacheName, BOOL async)
|
|||
@"take several seconds (or minutes on a slow machine with "
|
||||
@"lots of fonts)");
|
||||
}
|
||||
if (!env || !(path = [env objectForKey: @"GNUSTEP_SYSTEM_ROOT"]))
|
||||
path = [NSBundle _absolutePathOfExecutable: @"font_cacher"];
|
||||
if (path == nil)
|
||||
{
|
||||
path = [NSString stringWithCString:
|
||||
stringify_it(GNUSTEP_INSTALL_PREFIX)];
|
||||
NSLog(@"Could not find font_cacher program. Please run manually");
|
||||
return NO;
|
||||
}
|
||||
path = [path stringByAppendingPathComponent: @"Tools"];
|
||||
path = [path stringByAppendingPathComponent: @"font_cacher"];
|
||||
NSLog(@"Running %@", path);
|
||||
task = [NSTask launchedTaskWithLaunchPath: path
|
||||
arguments: [NSArray arrayWithObject: file_name]];
|
||||
if (task == nil || async == YES)
|
||||
|
|
|
@ -268,28 +268,6 @@ static Region emptyRegion;
|
|||
XChangeGC(XDPY, agcntxt, GCForeground, &gcv);
|
||||
}
|
||||
|
||||
- (void) setFont: (NSFont*)newFont
|
||||
{
|
||||
XGFontInfo *font_info;
|
||||
|
||||
if (font == newFont)
|
||||
return;
|
||||
|
||||
ASSIGN(font, newFont);
|
||||
|
||||
COPY_GC_ON_CHANGE;
|
||||
if (xgcntxt == 0)
|
||||
return;
|
||||
|
||||
font_info = (XGFontInfo *)[font fontInfo];
|
||||
[font_info setActiveFor: XDPY gc: xgcntxt];
|
||||
}
|
||||
|
||||
- (NSFont*) currentFont
|
||||
{
|
||||
return font;
|
||||
}
|
||||
|
||||
- (void) copyGraphicContext
|
||||
{
|
||||
GC source;
|
||||
|
@ -1400,6 +1378,23 @@ typedef enum {
|
|||
isRelative: NO];
|
||||
}
|
||||
|
||||
- (void) GSSetFont: (NSFont*)newFont
|
||||
{
|
||||
XGFontInfo *font_info;
|
||||
|
||||
if (font == newFont)
|
||||
return;
|
||||
|
||||
ASSIGN(font, newFont);
|
||||
|
||||
COPY_GC_ON_CHANGE;
|
||||
if (xgcntxt == 0)
|
||||
return;
|
||||
|
||||
font_info = (XGFontInfo *)[font fontInfo];
|
||||
[font_info setActiveFor: XDPY gc: xgcntxt];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Gstate operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
|
|
@ -39,7 +39,7 @@ TOOL_NAME = gpbs
|
|||
gpbs_OBJC_FILES = gpbs.m
|
||||
font_cacher_OBJC_FILES = font_cacher.m
|
||||
|
||||
ifneq ($(BUILD_X11),)
|
||||
ifeq ($(BUILD_GRAPHICS),xlib)
|
||||
TOOL_NAME += font_cacher
|
||||
gpbs_OBJC_FILES += xpbs.m
|
||||
ifeq ($(BACKEND_BUNDLE),yes)
|
||||
|
|
Loading…
Reference in a new issue