~ubuntu-branches/ubuntu/utopic/gnustep-back/utopic

« back to all changes in this revision

Viewing changes to Source/cairo/CairoGState.m

  • Committer: Package Import Robot
  • Author(s): Yavor Doganov
  • Date: 2014-07-07 16:00:20 UTC
  • mfrom: (4.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140707160020-0ukvke5ml6ibbezv
Tags: 0.24.0-2
* Upload to unstable; should finally fix the piuparts issue once
  mknfonts.tool is binNMUed (Closes: #663388).
* debian/compat: Bump to 9 to get .build-id debugging symbols.
* debian/control.m4 (Build-Depends): Require debhlper >= 9.
  (Description): Mention that the art backend is deprecated.
  (Suggests): Remove fonts-freefont-ttf as -common depends on it.
* debian/control: Regenerate.
* debian/rules (confflags): Define conditionally and pass --host to
  configure only if cross-compiling.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
1
2
/*
2
3
   CairoGState.m
3
4
 
73
74
    NSZoneFree(NSDefaultMallocZone(), _base); \
74
75
  }
75
76
 
76
 
static inline double doubleFromUserSpace(NSAffineTransform *ctm, double d)
 
77
static inline double doubleFromUserSpace(NSAffineTransform *ctm, CGFloat d)
77
78
{
78
79
  if (ctm)
79
80
    {
86
87
  return d;
87
88
}
88
89
 
89
 
static inline float floatToUserSpace(NSAffineTransform *ctm, double d)
 
90
static inline CGFloat floatToUserSpace(NSAffineTransform *ctm, double d)
90
91
{
91
92
  if (ctm)
92
93
    {
97
98
      d = doubleFromUserSpace(ictm, d);
98
99
      RELEASE(ictm);
99
100
    }
100
 
  return (float)d;
 
101
  return (CGFloat)d;
101
102
}
102
103
 
103
104
 
122
123
  [super dealloc];
123
124
}
124
125
 
 
126
- (NSString*) description
 
127
{
 
128
  NSMutableString *description = [[[super description] mutableCopy] autorelease];
 
129
  [description appendFormat: @" surface: %@",_surface];
 
130
  [description appendFormat: @" context: %p",_ct];
 
131
  return [[description copy] autorelease];
 
132
}
 
133
 
125
134
- (id) copyWithZone: (NSZone *)zone
126
135
{
127
136
  CairoGState *copy = (CairoGState *)[super copyWithZone: zone];
258
267
  return copy;
259
268
}
260
269
 
261
 
- (void) GSCurrentSurface: (CairoSurface **)surface: (int *)x : (int *)y
 
270
- (void) GSCurrentSurface: (CairoSurface **)surface : (int *)x : (int *)y
262
271
{
263
272
  if (x)
264
273
    *x = offset.x;
407
416
    }
408
417
}
409
418
 
410
 
- (void) GSSetFontSize: (float)size
 
419
- (void) GSSetFontSize: (CGFloat)size
411
420
{
412
421
  if (_ct)
413
422
    {
491
500
  if (_ct)
492
501
    {
493
502
      cairo_destroy(_ct);
 
503
      _ct = NULL;
494
504
    }
495
505
  if (!_surface)
496
506
    {
519
529
  cairo_new_path(_ct);
520
530
}
521
531
 
522
 
- (void) DPScurrentflat: (float *)flatness
 
532
- (void) DPScurrentflat: (CGFloat *)flatness
523
533
{
524
534
  if (_ct)
525
535
    {
526
 
      *flatness = (float)cairo_get_tolerance(_ct) * 2;
 
536
      *flatness = (CGFloat)cairo_get_tolerance(_ct) * 2;
527
537
    }
528
538
}
529
539
 
583
593
   */
584
594
}
585
595
 
586
 
- (void) DPScurrentlinewidth: (float *)width
 
596
- (void) DPScurrentlinewidth: (CGFloat *)width
587
597
{
588
598
  if (_ct)
589
599
    {
591
601
    }
592
602
}
593
603
 
594
 
- (void) DPScurrentmiterlimit: (float *)limit
 
604
- (void) DPScurrentmiterlimit: (CGFloat *)limit
595
605
{
596
606
  if (_ct)
597
607
    {
603
613
{
604
614
}
605
615
 
606
 
- (void) DPSsetdash: (const float *)pat : (int)size : (float)foffset
 
616
- (void) DPSsetdash: (const CGFloat *)pat : (NSInteger)size : (CGFloat)foffset
607
617
{
608
618
  if (_ct)
609
619
    {
623
633
    }
624
634
}
625
635
 
626
 
- (void) DPSsetflat: (float)flatness
 
636
- (void) DPSsetflat: (CGFloat)flatness
627
637
{
628
638
  [super DPSsetflat: flatness];
629
639
  if (_ct)
650
660
    }
651
661
}
652
662
 
653
 
- (void) DPSsetlinewidth: (float)width
 
663
- (void) DPSsetlinewidth: (CGFloat)width
654
664
{
655
665
  if (_ct)
656
666
    {
658
668
    }
659
669
}
660
670
 
661
 
- (void) DPSsetmiterlimit: (float)limit
 
671
- (void) DPSsetmiterlimit: (CGFloat)limit
662
672
{
663
673
  if (_ct)
664
674
    {
676
686
 
677
687
- (void) _setPath
678
688
{
679
 
  unsigned count = [path elementCount];
680
 
  unsigned i;
 
689
  NSInteger count = [path elementCount];
 
690
  NSInteger i;
681
691
  SEL elmsel = @selector(elementAtIndex:associatedPoints:);
682
 
  IMP elmidx = [path methodForSelector: elmsel];
 
692
  NSBezierPathElement (*elmidx)(id, SEL, NSInteger, NSPoint*) =
 
693
    (NSBezierPathElement (*)(id, SEL, NSInteger, NSPoint*))[path methodForSelector: elmsel];
683
694
 
684
695
  // reset current cairo path
685
696
  cairo_new_path(_ct);
992
1003
  cairo_fill(_ct);
993
1004
}
994
1005
 
995
 
- (void) DPSimage: (NSAffineTransform *)matrix : (int)pixelsWide
996
 
                 : (int)pixelsHigh : (int)bitsPerSample 
997
 
                 : (int)samplesPerPixel : (int)bitsPerPixel
998
 
                 : (int)bytesPerRow : (BOOL)isPlanar
 
1006
- (void) DPSimage: (NSAffineTransform *)matrix : (NSInteger)pixelsWide
 
1007
                 : (NSInteger)pixelsHigh : (NSInteger)bitsPerSample 
 
1008
                 : (NSInteger)samplesPerPixel : (NSInteger)bitsPerPixel
 
1009
                 : (NSInteger)bytesPerRow : (BOOL)isPlanar
999
1010
                 : (BOOL)hasAlpha : (NSString *)colorSpaceName
1000
1011
                 : (const unsigned char *const[5])data
1001
1012
{
1159
1170
    cairo_matrix_init_scale(&source_matrix, 1, -1);
1160
1171
    cairo_matrix_translate(&source_matrix, 0, -pixelsHigh);
1161
1172
    cairo_pattern_set_matrix(cpattern, &source_matrix);
 
1173
    cairo_pattern_set_filter(cpattern, CAIRO_FILTER_BILINEAR);
1162
1174
    if (cairo_version() >= CAIRO_VERSION_ENCODE(1, 6, 0))
1163
1175
      {
1164
1176
        cairo_pattern_set_extend(cpattern, CAIRO_EXTEND_PAD);
1188
1200
      device_color_t c;
1189
1201
 
1190
1202
      cairo_save(_ct);
1191
 
      _set_op(_ct, op);
1192
 
 
1193
 
      c = fillColor;
1194
 
      gsColorToRGB(&c);
1195
 
      // The underlying concept does not allow to determine if alpha is set or not.
1196
 
      cairo_set_source_rgba(_ct, c.field[0], c.field[1], c.field[2], c.field[AINDEX]);
 
1203
 
 
1204
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 9, 4)
 
1205
      if (GSCompositeHighlight == op)
 
1206
        {
 
1207
          cairo_set_operator(_ct, CAIRO_OPERATOR_DIFFERENCE);
 
1208
          cairo_set_source_rgb(_ct, 1, 1, 1);
 
1209
        }
 
1210
      else
 
1211
#endif
 
1212
        {
 
1213
          _set_op(_ct, op);
 
1214
          
 
1215
          c = fillColor;
 
1216
          gsColorToRGB(&c);
 
1217
          // The underlying concept does not allow to determine if alpha is set or not.
 
1218
          cairo_set_source_rgba(_ct, c.field[0], c.field[1], c.field[2], c.field[AINDEX]);
 
1219
        }
 
1220
 
1197
1221
      // This is almost a rectclip::::, but the path stays unchanged.
1198
1222
      path = [NSBezierPath bezierPathWithRect: aRect];
1199
1223
      [path transformUsingAffineTransform: ctm];
1209
1233
                fromRect: (NSRect)srcRect 
1210
1234
                 toPoint: (NSPoint)destPoint 
1211
1235
                      op: (NSCompositingOperation)op
1212
 
                fraction: (float)delta
 
1236
                fraction: (CGFloat)delta
1213
1237
{
1214
1238
  cairo_surface_t *src;
1215
1239
  NSSize ssize = NSZeroSize;
1237
1261
  cairo_pattern_t *cpattern;
1238
1262
  cairo_matrix_t source_matrix;
1239
1263
 
 
1264
  NSDebugMLLog(@"CairoGState", @"self: %@\n", self);
 
1265
 
1240
1266
  if (!_ct || !source->_ct)
1241
1267
    {
1242
1268
      return;
1319
1345
  //cairo_matrix_translate(&source_matrix, 0,  -[_surface size].height);
1320
1346
  cairo_matrix_translate(&source_matrix, minx - x + dx, miny - y + dy - ssize.height);
1321
1347
  cairo_pattern_set_matrix(cpattern, &source_matrix);
 
1348
  cairo_pattern_set_filter(cpattern, CAIRO_FILTER_BILINEAR);
1322
1349
  cairo_set_source(_ct, cpattern);
1323
1350
  cairo_pattern_destroy(cpattern);
1324
1351
  cairo_rectangle(_ct, x, y, width, height);
1348
1375
           fromRect: (NSRect)aRect 
1349
1376
            toPoint: (NSPoint)aPoint 
1350
1377
                 op: (NSCompositingOperation)op
1351
 
           fraction: (float)delta
 
1378
           fraction: (CGFloat)delta
1352
1379
{
1353
1380
  NSAffineTransformStruct tstruct =  [ctm transformStruct];
1354
1381
  cairo_surface_t *src;
1358
1385
  cairo_matrix_t local_matrix;
1359
1386
  cairo_matrix_t source_matrix;
1360
1387
 
 
1388
  NSDebugMLLog(@"CairoGState", @"source: %@ fromRect: %@ toPoint: %@\n",
 
1389
               source,
 
1390
               NSStringFromRect(aRect),
 
1391
               NSStringFromPoint(aPoint));
 
1392
  
1361
1393
  if (!_ct || !source->_ct)
1362
1394
    {
1363
1395
      NSLog(@"WARNING: -drawGState called with a NULL target context (%p) or source context (%p)",
1405
1437
  cairo_matrix_init_scale(&source_matrix, 1, -1);
1406
1438
  cairo_matrix_translate(&source_matrix, 0, -[source->_surface size].height);
1407
1439
  cairo_pattern_set_matrix(cpattern, &source_matrix);
 
1440
  cairo_pattern_set_filter(cpattern, CAIRO_FILTER_BILINEAR);
1408
1441
  if (cairo_version() >= CAIRO_VERSION_ENCODE(1, 6, 0))
1409
1442
    {
1410
1443
      cairo_pattern_set_extend(cpattern, CAIRO_EXTEND_PAD);
1575
1608
          double green;
1576
1609
          double blue;
1577
1610
          double alpha;
1578
 
          
 
1611
          NSString *colorSpaceName;
 
1612
          
1579
1613
          [gradient getColor: &color
1580
1614
                    location: &location
1581
1615
                     atIndex: i];
1582
 
          red = [color redComponent];
1583
 
          green = [color greenComponent];
1584
 
          blue = [color blueComponent];
1585
 
          alpha = [color alphaComponent];
1586
 
          cairo_pattern_add_color_stop_rgba(cpattern, location,
1587
 
                                            red, green, blue, alpha);
 
1616
 
 
1617
          colorSpaceName = [color colorSpaceName];
 
1618
          if([NSCalibratedRGBColorSpace isEqualToString: colorSpaceName] ||
 
1619
             [NSDeviceRGBColorSpace isEqualToString: colorSpaceName])
 
1620
            {
 
1621
              red = [color redComponent];
 
1622
              green = [color greenComponent];
 
1623
              blue = [color blueComponent];
 
1624
              alpha = [color alphaComponent];
 
1625
              cairo_pattern_add_color_stop_rgba(cpattern, location,
 
1626
                                                red, green, blue, alpha);
 
1627
            }
 
1628
          else if([NSCalibratedWhiteColorSpace isEqualToString: colorSpaceName] ||
 
1629
                  [NSDeviceWhiteColorSpace isEqualToString: colorSpaceName] ||
 
1630
                  [NSCalibratedBlackColorSpace isEqualToString: colorSpaceName] ||
 
1631
                  [NSDeviceBlackColorSpace isEqualToString: colorSpaceName])
 
1632
            {
 
1633
              red = [color whiteComponent];
 
1634
              green = [color whiteComponent];
 
1635
              blue = [color whiteComponent];
 
1636
              alpha = [color alphaComponent];
 
1637
              cairo_pattern_add_color_stop_rgba(cpattern, location,
 
1638
                                                red, green, blue, alpha);
 
1639
            }
 
1640
          else
 
1641
            {
 
1642
              NSLog(@"Cannot draw gradient for %@",colorSpaceName); 
 
1643
            }
1588
1644
        }
1589
1645
      
1590
1646
      cairo_save(_ct);