GithubHelp home page GithubHelp logo

splashdust / svgquartzrenderer Goto Github PK

View Code? Open in Web Editor NEW
119.0 119.0 14.0 6.92 MB

Simple SVG renderer implemented in Obj-C using CoreGraphics

Home Page: http://www.splashdust.net/2010/09/svgquartzrenderer-a-basic-iphone-sdk-compatible-svg-renderer/

License: MIT License

Objective-C 100.00%

svgquartzrenderer's People

Contributors

boxerab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

svgquartzrenderer's Issues

build error on osx 10.6 with xcode 3.2.4

I can't seem to get this to build. I am getting the
"Cocoa/Cocoa.h no such file or directory" error.

This is on a clean pull from github; I have not changed any of the build settings.

Any guidance on this issue would be greatly appreciated.

Thanks!

Project won't build out of the box - missing files, missing targets

  1. Clone the github repos
  2. Open the xcodeproj file in Xcode4
  3. ...no iOS targets, only a macosx target
  4. <libxml/tree.h> is "missing"
  5. GraphicFrag.h file is "missing"
  6. UIKit reference in one file (fails because this isn't an iOS project)

Are there setup instructions somewhere? Nothing on the front page of the github repository :(

Possible bug in applyTransformations

In SVGQuartzRenderer.m/applyTransformations function under AFFINE if statement there are the following lines:

a = 1;
b /= d;
c /= a;
d = 1;

Don't know (or want to know) what is really going on in this function but it looks like variable "c" will remain unchanged no matter what. Is this a bug?

Color names ignored

Color names "blue", "black", etc. are ignored by the renderer (at least for the "fill" attribute). Setting hex values for colors works.

Problems building SGRenderTouch project

FYI for anyone having issues building the SGRenderTouch project on Xcode 4.2 on Snow Leopard:

-No deployment target set: Set deployment target to 4.2 on project summary page.

-MROGeometry files missing: Download frm git hub and place in directory shown in project.

-libxml2.2.dylib was not found. Located path at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk/usr/lib/

-Error SVGRenderTouch.pch has been modified since the precompiled header was built. Menu, Product, Clean fixed.

-CGPathReader line causing an error
PathParser *p = [alloc (PathParser) init];
Changed to
PathParser *p = [[PathParser alloc] init];

-Same kind of thing in PathParser.m
PathBuilder *pb = [[alloc (PathBuilder) initwithTrafo:trafo] autorelease];
replaced with
PathBuilder *pb = [[[PathBuilder alloc] initwithTrafo:trafo] autorelease];

-In PathParser.m commented lines:
//DEBUG_TIMER_START();
//DEBUG_TIMER_LOG();
as they caused errors in PathParser.rl I didn't understand

-In GraphicFrag.h removed 'const' from beginning of line
const enum TRANSFORMATION_TYPE {TRANS,ROT,SCALE,AFFINE};
to get rid of warnings.

Project ran fine after these changes.

Would like to know if any of these changes will cause problems later?

If not they are listed for those new to apple development to save some time.

Hierarchical transforms aren't handled

When parsing the xml of a svg file when a transform is encountered in SVGQuartzRenderer.m/applyTransformation the code first wipes out any prior transforms with;

CGContextConcatCTM(cgContext, CGAffineTransformInvert(transform));
transform = CGAffineTransformIdentity;

then applies the current transform to the context.

I need to apply all transforms within an item's xml hierarchy applying them in startElementSAX and undoing them in endElementSAX. Not just the last one.

Do you have any code to do this already written?

Same for styles???

SVGQuartzRenderer::parse is not thread safe

Integrating the code and just noticed that the svgXml variable with class scope is allocated and released within the parse method. Concurrent calls to this method would corrupt this variable. It might be a good idea to address this or put a comment just to set expectations for integrators.

Multibyte characters support

Hi,

I found your source does not support multi-byte characters like Japanese.
I suggest you to handle text with UIKit API, because
some functions (e.g. CGContextSelectFont() ) do not treat several languages well.
I wrote a experimental code applyed this like below.
This change enables rendering text contains UTF-8 multibyte characters.
I hope this helps...


diff --git a/SVGRendererTouch/Classes/SVGStyle.m b/SVGRendererTouch/Classes/SVGStyle.m
index 8221a57..7d6d651 100644
--- a/SVGRendererTouch/Classes/SVGStyle.m
+++ b/SVGRendererTouch/Classes/SVGStyle.m
@@ -42,6 +42,8 @@

 @end

+static NSString* DefaultFontName = @"Helvetica";
+
 @implementation SVGStyle

 @synthesize fillGradientPoints;
@@ -413,7 +415,7 @@
                 break;
          case ';':
                 //parse line
-                [self parseStyle:styleBegin :styleColon-1 :styleColon+1 :styleEnd :defDict];
+                [self parseStyle:styleBegin :styleColon-1 :styleColon+1 :styleEnd-1 :defDict];
                 newLine = true;                
                 break;
         default:
@@ -736,14 +738,18 @@

 - (void)drawText:(char*)text :(CGPoint)location  withContext:(CGContextRef)context
 {
-    if(font)
-        self.font = @"Helvetica";

-    CGContextSetRGBFillColor(context, fillColor.r, fillColor.g, fillColor.b, fillColor.a);
+    UIGraphicsPushContext(context);

-    CGContextSelectFont(context, [font UTF8String], fontSize, kCGEncodingMacRoman);
-    CGContextSetFontSize(context, fontSize);
-    CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0, -1.0));
+    CGContextSetRGBFillColor(context, fillColor.r, fillColor.g, fillColor.b, fillColor.a);
+    NSAutoreleasePool* arp = [NSAutoreleasePool new];
+    UIFont* tFont = nil;
+    if (font) {
+        // // TODO: Using alternative font if style(italic/oblique) or weight is specified.
+        // NSLog(@"fontnames for family name (%@) => %@", font, [UIFont fontNamesForFamilyName:font]);
+        tFont = [UIFont fontWithName:font size:fontSize];
+    }
+    if (!tFont) tFont = [UIFont fontWithName:DefaultFontName size:fontSize];

     [self setUpStroke:context];

@@ -757,12 +763,15 @@
         drawingMode = kCGTextStroke;

     CGContextSetTextDrawingMode(context, drawingMode);
-    CGContextShowTextAtPoint(context,
-                             location.x,
-                             location.y,
-                             (const char*)text,
-                             strlen(text));     

+    NSString* str = [NSString stringWithUTF8String:text];
+    CGSize textSize = [str sizeWithFont:tFont]; 
+    CGRect textRect = CGRectMake(location.x, location.y, textSize.width, textSize.height);
+    [str drawInRect:textRect withFont:tFont lineBreakMode:UILineBreakModeClip alignment:UITextAlignmentLeft];
+    [arp release];
+    
+    UIGraphicsPopContext();
+
 }

 // Draw a path based on style information

svgDrawing release

You are releasing svgDrawing twice inside SVGRenderViewTouch
Inside svgRenderer: and inside dealloc, it was making my program to crash.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.