Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7626535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:20:18+00:00 2026-05-31T05:20:18+00:00

Given an SVG Path element, how can I convert all path commands into absolute

  • 0

Given an SVG Path element, how can I convert all path commands into absolute coordinates? For example, convert this path:

<path d="M17,42 l100,0 v100 h-100 z"/>

into this equivalent path:

<path d="M17,42 L117,42 V142 H17 Z"/>

This question was motivated by this question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:20:19+00:00Added an answer on May 31, 2026 at 5:20 am

    Here’s the JavaScript code I came up with:

    function convertToAbsolute(path){
      var x0,y0,x1,y1,x2,y2,segs = path.pathSegList;
      for (var x=0,y=0,i=0,len=segs.numberOfItems;i<len;++i){
        var seg = segs.getItem(i), c=seg.pathSegTypeAsLetter;
        if (/[MLHVCSQTA]/.test(c)){
          if ('x' in seg) x=seg.x;
          if ('y' in seg) y=seg.y;
        }else{
          if ('x1' in seg) x1=x+seg.x1;
          if ('x2' in seg) x2=x+seg.x2;
          if ('y1' in seg) y1=y+seg.y1;
          if ('y2' in seg) y2=y+seg.y2;
          if ('x'  in seg) x+=seg.x;
          if ('y'  in seg) y+=seg.y;
          switch(c){
            case 'm': segs.replaceItem(path.createSVGPathSegMovetoAbs(x,y),i);                   break;
            case 'l': segs.replaceItem(path.createSVGPathSegLinetoAbs(x,y),i);                   break;
            case 'h': segs.replaceItem(path.createSVGPathSegLinetoHorizontalAbs(x),i);           break;
            case 'v': segs.replaceItem(path.createSVGPathSegLinetoVerticalAbs(y),i);             break;
            case 'c': segs.replaceItem(path.createSVGPathSegCurvetoCubicAbs(x,y,x1,y1,x2,y2),i); break;
            case 's': segs.replaceItem(path.createSVGPathSegCurvetoCubicSmoothAbs(x,y,x2,y2),i); break;
            case 'q': segs.replaceItem(path.createSVGPathSegCurvetoQuadraticAbs(x,y,x1,y1),i);   break;
            case 't': segs.replaceItem(path.createSVGPathSegCurvetoQuadraticSmoothAbs(x,y),i);   break;
            case 'a': segs.replaceItem(path.createSVGPathSegArcAbs(x,y,seg.r1,seg.r2,seg.angle,seg.largeArcFlag,seg.sweepFlag),i);   break;
            case 'z': case 'Z': x=x0; y=y0; break;
          }
        }
        // Record the start of a subpath
        if (c=='M' || c=='m') x0=x, y0=y;
      }
    }
    

    Used like so with the path from the question:

    var path = document.querySelector('path');
    convertToAbsolute(path);
    console.log(path.getAttribute('d'));
    // M 17 42 L 117 42 V 142 H 17 Z
    

    Edit: Here’s a test page with a path that includes every command (absolute and relative) interleaved and shows that the conversion works in the now-current versions of IE, Chrome, FF, and Safari.
    http://phrogz.net/svg/convert_path_to_absolute_commands.svg

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a package, how can I automatically find all its sub-packages?
In a SVG document, I want to make a <path> -element transparent. I tried
Given this markup: // Calendar.html?date=1/2/2003 <script> $(function() { $('.inlinedatepicker').datepicker(); }); </script> ... <div class=inlinedatepicker
Given this XML: <?xml version=1.0 encoding=utf-8?> <content dataType=XML> <item type=Promotion name=Sample Promotion expires=04/01/2009> <![CDATA[
Given an NSApp object (aka [NSApplication sharedApplication]), how can I get the currently active
i am trying to rotate circle on a elliptrical path using svg animation, the
Given a set of floorplans (in Autocad, svg, or whatever format need be...), I
How can I make a SVG appear reliably without scrollbars in HTML? Something that
I have body { background: url(images/background.svg); } The desired effect is that this background
Given an existing valid SVG document, what's the best way to create informational popups,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.