OWL ITS + 탐지시스템(인터넷 진흥원)
jhjang
2021-10-14 b74776268dd3eb2bc57744928d6f7150ffcd4ec2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function handleFileSelect(evt) {
  const $el = $('#filereader');
  const files = evt.target.files;
  files.forEach(file => {
    const reader = new FileReader();
    reader.onload = e => {
      $el.find('.load-target').html(e.target.result);
      svgAsPngUri($el.find('.load-target svg')[0], null, uri => {
        $el.find('input').hide()
        $el.find('.preview').html('<img src="' + uri + '" />');
      });
      $el.find('.save').click(() => saveSvgAsPng($el.find('.load-target svg')[0], 'test.png'));
    };
    reader.readAsText(f);
  });
}
 
if (window.File && window.FileReader && window.FileList && window.Blob) {
  document.getElementById('file').addEventListener('change', handleFileSelect, false);
}
 
function inlineTest(title, $el, saveOptions, testOptions) {
  const svg = $el.html();
  const template = $('#inline-template').html();
  const row = $el.html(template);
  row.find('h2').text(title);
  row.find('.canvas').html(svg);
 
  const canvas = row.find(testOptions && testOptions.selector || 'svg')[0];
  svgAsPngUri(canvas, saveOptions)
    .then(uri => row.find('.preview').html('<img src="' + uri + '" />'));
 
  row.find('.save').click(() => saveSvgAsPng(canvas, 'test.png', saveOptions));
}
 
inlineTest('Directly in the HTML', $('#inline'));
inlineTest('With linked PNG image', $('#embedded-png'));
inlineTest('With linked SVG image', $('#embedded-svg'));
inlineTest('Sized with pixels', $('#sized-with-pixels'));
inlineTest('Sized with style', $('#sized-with-style'));
inlineTest('Sized with CSS', $('#sized-with-css'));
inlineTest('At a higher resolution', $('#scaling'), {scale: 2});
inlineTest('When CSS styling selectors are prefixed', $('#selectors-prefixed'), {
  selectorRemap: s => s.replace('#selectors-prefixed ', '')
});
inlineTest('Modifying the style', $('#modified-style'), {
  modifyStyle: s => s.replace('green', 'red')
});
inlineTest('Modifying the whole CSS rule', $('#modified-css'), {
  modifyCss: (selector, properties) => {
    selector = selector.replace('#selectors-prefixed ', '');
    properties = properties.replace('green', 'blue');
    return selector + '{' + properties + '}';
  }
});
inlineTest('Exporting a group within an SVG', $('#group'), null, {
  selector: '#sub-group'
});
inlineTest('Percentage Height and Width', $('#percentage-size'));
inlineTest('Background color', $('#background-color'), {backgroundColor: 'lightblue'});
inlineTest('Pan and Zoom', $('#pan-and-zoom'), {
  left: -50,
  top: -50,
  width: 300,
  height: 300
});
inlineTest('With Unicode characters', $('#unicode'));
inlineTest('With gradients', $('#gradient'));
inlineTest('With foreign objects', $('#foreign-object'));
inlineTest('With opacity', $('#opacity'));
inlineTest('When setting xmlns on foreign object children', $('#xmlns-override'));
inlineTest('When using HTML entites', $('#entities'));
inlineTest('Transformed text', $('#transformed-text'));
inlineTest('With custom fonts', $('#custom-font'));
 
const $sandbox = $('#sandbox');
$sandbox.find('.render').click(() => {
  $sandbox.find('.error').hide().text('');
  $sandbox.find('.load-target').html($('#sandbox textarea').val());
  const canvas = $sandbox.find('.load-target svg')[0];
  try {
    svgAsPngUri(canvas, null, uri => $sandbox.find('.preview').html('<img src="' + uri + '" />'));
    $sandbox.find('.save').unbind('click').click(() => saveSvgAsPng(canvas, 'test.png'));
  } catch(err) {
    $sandbox.find('.error').show().text(err.message);
    $sandbox.find('.preview').html('');
  }
});