Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Support for SVG in HTML

    SmartClient Version: v9.1p_2015-09-16/Pro Development Only (built 2015-09-16)

    Google Chrome version 46

    SmartClient adds all images as an <img> tag in the HTML contents. I would like to modify SVG files using CSS but the SVG files are loaded into the DOM using the <img> tag. This apparently does not allow modification of SVG using CSS. I have tried editing the function getInnerHTML() to replace the <img> tag with <object> tag (and changing src to data) but the result was unsatisfactory. It seems that having the <svg> inline with HTML will allow SVG modification using CSS (see the HTMLFlow example below). I was wondering if we could change the way SmartClient adds its images to the DOM so that we could potentially add the SVG inline with HTML by specifying the SVG file (see the button example below). This could be done by getting the contents of the SVG file and adding it directory into the HTML instead of using the <img> tag.

    Demo is available at this link on SmartClient Feature Explorer using the following code snippets:
    https://www.smartclient.com/docs/9.1...er.html#styles

    JavaScript: (exampleText variable contains the contents in an SVG file)
    Code:
    exampleText = '<svg version="1.1" id="Layer_1" xmlns="[URL]http://www.w3.org/2000/svg[/URL]" xmlns:xlink="[URL]http://www.w3.org/1999/xlink[/URL]" x="0px" y="0px"'+
       'width="612px" height="502.174px" viewBox="0 65.326 612 502.174" enable-background="new 0 65.326 612 502.174"'+
       'xml:space="preserve" class="logo">'+
    '<ellipse class="ground" cx="283.5" cy="487.5" rx="259" ry="80"/>'+
    '<path class="kiwi" d="M210.333,65.331C104.367,66.105-12.349,150.637,1.056,276.449c4.303,40.393,18.533,63.704,52.171,79.03'+
    '  c36.307,16.544,57.022,54.556,50.406,112.954c-9.935,4.88-17.405,11.031-19.132,20.015c7.531-0.17,14.943-0.312,22.59,4.341'+
    '  c20.333,12.375,31.296,27.363,42.979,51.72c1.714,3.572,8.192,2.849,8.312-3.078c0.17-8.467-1.856-17.454-5.226-26.933'+
    '  c-2.955-8.313,3.059-7.985,6.917-6.106c6.399,3.115,16.334,9.43,30.39,13.098c5.392,1.407,5.995-3.877,5.224-6.991'+
    '  c-1.864-7.522-11.009-10.862-24.519-19.229c-4.82-2.984-0.927-9.736,5.168-8.351l20.234,2.415c3.359,0.763,4.555-6.114,0.882-7.875'+
    '  c-14.198-6.804-28.897-10.098-53.864-7.799c-11.617-29.265-29.811-61.617-15.674-81.681c12.639-17.938,31.216-20.74,39.147,43.489'+
    '  c-5.002,3.107-11.215,5.031-11.332,13.024c7.201-2.845,11.207-1.399,14.791,0c17.912,6.998,35.462,21.826,52.982,37.309'+
    '  c3.739,3.303,8.413-1.718,6.991-6.034c-2.138-6.494-8.053-10.659-14.791-20.016c-3.239-4.495,5.03-7.045,10.886-6.876'+
    '  c13.849,0.396,22.886,8.268,35.177,11.218c4.483,1.076,9.741-1.964,6.917-6.917c-3.472-6.085-13.015-9.124-19.18-13.413'+
    '  c-4.357-3.029-3.025-7.132,2.697-6.602c3.905,0.361,8.478,2.271,13.908,1.767c9.946-0.925,7.717-7.169-0.883-9.566'+
    '  c-19.036-5.304-39.891-6.311-61.665-5.225c-43.837-8.358-31.554-84.887,0-90.363c29.571-5.132,62.966-13.339,99.928-32.156'+
    '  c32.668-5.429,64.835-12.446,92.939-33.85c48.106-14.469,111.903,16.113,204.241,149.695c3.926,5.681,15.819,9.94,9.524-6.351'+
    '  c-15.893-41.125-68.176-93.328-92.13-132.085c-24.581-39.774-14.34-61.243-39.957-91.247'+
    '  c-21.326-24.978-47.502-25.803-77.339-17.365c-23.461,6.634-39.234-7.117-52.98-31.273C318.42,87.525,265.838,64.927,210.333,65.331'+
    '  z M445.731,203.01c6.12,0,11.112,4.919,11.112,11.038c0,6.119-4.994,11.111-11.112,11.111s-11.038-4.994-11.038-11.111'+
    '  C434.693,207.929,439.613,203.01,445.731,203.01z"/>'+
    '<filter id="pictureFilter" >'+
    '  <feGaussianBlur stdDeviation="15" />'+
    '</filter>'+
    '</svg>'
     
     
    isc.HTMLFlow.create({
        ID:"textBox",
        left:100, width:300,
        contents:exampleText
    });
     
    isc.Button.create({
    icon: "[URL]http://s.cdpn.io/3/kiwi.svg[/URL]"
    });
    CSS:
    Code:
    .logo {
      width: 200px;
      height: 164px;
    }
     
    .kiwi {
      fill: #94d31b;
      
      // stroke: #909;
                    // stroke-width: 10;
     
      // not sure which of these is correct
      // stroke-linejoin: butt | round | square;
      // stroke-linecap: butt | round | square;
     
      // stroke-dasharray: 5, 5, 10;
     
      // filter: url(#pictureFilter);
      // mask: url(#f1);
      // clip-path: url();
    }
    .kiwi:hover {
      fill: #ace63c;
    }
     
    .ground {
      fill: #787f6a;
    }
    .ground:hover {
      filter: url(#pictureFilter);
      fill: #896d3d;
    }
     
    body {
      padding: 20px;
    }
    Related post: http://forums.smartclient.com/forum/...rrent-browsers

    #2
    You can use a "data:" URL to embed an SVG. - the CSS looks like "url('data:image/svg+xml;base64,PD94bWwgdmVy...". Google for further details and some tools that can help you generate the appropriate CSS from an input SVG. Be aware that this has implications in terms of browser support for your application (again, Google for details).

    Comment


      #3
      I have an example of using data URI to embed the image but the CSS does not get modified if attempting to add CSS rules to image. The intent is to have the SVG image change its CSS styling (ground class) depending on its parent style class. The expected result is the ground should be blue since the styling for ".container .ground" is valid. The current result is gray which is its default. This seems to be a limitation in regards to modifying the contents of the SVG encapsulated in an <img> tag from the generated HTML of SmartClient components. Would the intent of having the SVG modified through CSS based on its parent style class, be possible?

      JavaScript (the layout uses a "container" style class and the image uses the "demo" style class which contains the SVG)
      Code:
      isc.VLayout.create({
          width: "100%",
          height: "100%",
          styleName: "container",
          members: [
              isc.Img.create({
                  width: "100%",
                  height: "100%",
                  baseStyle: "demo"
              })
          ]
      });
      CSS ("ground" style class is used for the ground section of the image)
      Code:
      .container:
      {
          background: yellow;
      }
      
      .demo
      {
      background: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNi4wLjQsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwh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Y3YzkuOTQ2LTAuOTI1LDcuNzE3LTcuMTY5LTAuODgzLTkuNTY2DQoJYy0xOS4wMzYtNS4zMDQtMzkuODkxLTYuMzExLTYxLjY2NS01LjIyNWMtNDMuODM3LTguMzU4LTMxLjU1NC04NC44ODcsMC05MC4zNjNjMjkuNTcxLTUuMTMyLDYyLjk2Ni0xMy4zMzksOTkuOTI4LTMyLjE1Ng0KCWMzMi42NjgtNS40MjksNjQuODM1LTEyLjQ0Niw5Mi45MzktMzMuODVjNDguMTA2LTE0LjQ2OSwxMTEuOTAzLDE2LjExMywyMDQuMjQxLDE0OS42OTVjMy45MjYsNS42ODEsMTUuODE5LDkuOTQsOS41MjQtNi4zNTENCgljLTE1Ljg5My00MS4xMjUtNjguMTc2LTkzLjMyOC05Mi4xMy0xMzIuMDg1Yy0yNC41ODEtMzkuNzc0LTE0LjM0LTYxLjI0My0zOS45NTctOTEuMjQ3DQoJYy0yMS4zMjYtMjQuOTc4LTQ3LjUwMi0yNS44MDMtNzcuMzM5LTE3LjM2NWMtMjMuNDYxLDYuNjM0LTM5LjIzNC03LjExNy01Mi45OC0zMS4yNzNDMzE4LjQyLDg3LjUyNSwyNjUuODM4LDY0LjkyNywyMTAuMzMzLDY1LjMzMQ0KCXogTTQ0NS43MzEsMjAzLjAxYzYuMTIsMCwxMS4xMTIsNC45MTksMTEuMTEyLDExLjAzOGMwLDYuMTE5LTQuOTk0LDExLjExMS0xMS4xMTIsMTEuMTExcy0xMS4wMzgtNC45OTQtMTEuMDM4LTExLjExMQ0KCUM0MzQuNjkzLDIwNy45MjksNDM5LjYxMywyMDMuMDEsNDQ1LjczMSwyMDMuMDF6Ii8+DQo8L3N2Zz4NCg==") no-repeat;
      }
      
      .ground
      {
          fill: green !important;
      }
      
      .container .ground
      {
          fill: blue !important;
      }

      Comment


        #4
        That's not a SmartClient limitation, that's just how "data:" URLs work in the browser. To create a stateful image, you take advantage of the fact that SmartClient controls are already stateful, and use different CSS classes for different states, embedding a slightly different data URL for each state.

        Comment

        Working...
        X