Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- void SvgWork(string input, string output, float kx, float ky)
- {
- char
- ch,
- *outfile = new char[output.length() + 1];
- ifstream fin;
- FILE *fout;
- string
- key_osvg = "<svg",
- key_csvg = "</sv",
- key_obody = "<body",
- key_cbody = "</bod",
- atribute,
- to_out,
- values,
- values_changed,
- bword,
- word;
- bool
- figure2 = false,
- atag_open = false,
- atag_close = false,
- btag_open = false,
- btag_close = false,
- ctag_open = false,
- ctag_close = false,
- first_exit = false,
- firstcloser=false,
- is = false,
- space = false,
- wdot1 = false,
- wdot2 = false,
- body = false,
- svg = false;
- int
- j = 0,
- M = 4,
- i = 0,
- ctags_closecount=0,
- N = 6;
- float k = kx < ky ? kx : ky;
- outfile = stoch(output);
- fin.open(input);
- fopen_s(&fout, outfile, "w");
- if (!fin.is_open())
- {
- cout << "Ошибка открытия файла!" << endl; fin.close(); fclose(fout);
- }
- else
- {
- while (fin.get(ch))
- {
- /* body */
- if (body)
- {
- /* Внутри тега */
- if (ch == '<')
- {
- btag_open = true;
- btag_close = false;
- first_exit = false;
- }
- if (ch == '>')
- {
- btag_open = false;
- btag_close = true;
- }
- /* Фильтр на позицию внутри тега svg */
- if (btag_open && !btag_close)
- {
- if ((j < M) && !first_exit)
- {
- ++j;
- bword += ch;
- }
- else
- {
- if (bword == key_osvg)
- {
- for (int i=0;i< bword.length()-1;++i)
- fprintf(fout, "%c", bword[i]);
- fprintf(fout, "%c", '\"');
- //cout << stoch(bword);
- svg = true;
- }
- if (bword == key_csvg)
- {
- fprintf(fout, "%c", 'g');
- fprintf(fout, "%c", '>');
- svg = false;
- }
- first_exit = true;
- bword = "";
- j = 0;
- }
- }
- /* svg */
- if (svg)
- {
- if (ch == '>') {
- ctag_close = true;
- ctag_open = false;
- }
- if (ch == '<') {
- ctag_close = false;
- ctag_open = true;
- }
- if ((ctag_close)&&(ch=='>')) {
- ctags_closecount++;
- }
- if ((ctags_closecount == 1) && (ch >= 'a') && (ch <= 'z')) {
- fprintf(fout, "%c", '<');
- //cout << "<";
- ctags_closecount++;
- }
- if (wdot2)
- {
- values_changed = ChangeSvg(atribute, values, k);
- to_out = atribute + '=' + '\"' + values_changed + '\"';
- //cout<<to_out<<endl;
- char *outword = new char[to_out.length + 1];
- outword = stoch(to_out);
- for (int k= 0; k <= to_out.length(); ++i) {
- fprintf(fout, "&c", outword[k]);
- cout << outword[k];
- }
- fprintf(fout, "&s", outword);
- cout << "!";
- cout << endl;
- //cout << stoch(to_out);
- atribute = values = "";
- is = space = wdot1 = wdot2 = false;
- }
- if (!space && !wdot2&& ch != '<') fprintf(fout, "%c", ch);
- /* Атрибут */
- if (ch == '=')
- is = true;
- if (space && !is)
- atribute += ch;
- /* Значение атрибута */
- if (wdot1 && !wdot2 && ch != '\"') values += ch;
- if (ch == '\"' && wdot1) wdot2 = true;
- if (ch == '\"' && !wdot1) wdot1 = true;
- if (ch == ' ' && !wdot1 && !wdot2) space = true;
- if (ch == '<') { space = false; atribute = ""; }
- if (ch == '<' && figure2) fprintf(fout, "%с", ch);
- if (ch == '<' && !figure2) figure2 = true;
- }
- else
- {
- fprintf(fout, "%c", ch);
- }
- }
- else fprintf(fout, "%c", ch);
- /* Внутри тега */
- if (ch == '<')
- {
- atag_open = true;
- atag_close = false;
- }
- if (ch == '>')
- {
- atag_close = true;
- atag_open = false;
- word = "";
- i = 0;
- }
- /* Фильтр на позицию внутри тега <body> */
- if (atag_open && !atag_close)
- {
- if (i < N)
- {
- word += ch;
- ++i;
- if (word == key_obody)
- body = true;
- if (word == key_cbody)
- body = false;
- }
- else
- {
- word = "";
- i = 0;
- }
- }
- }
- }
- fin.close();
- fclose(fout);
- }
- /* Меняет значения атрибутов svg */
- string ChangeSvg(string name, string value, float k)
- {
- string result;
- if (CmprSvg(name))
- {
- result = ChangeNumSvg(value, k);
- return result;
- }
- return value;
- }
- /* Сравнивает атрибут с библиотекой изменяемых атрибутов */
- bool CmprSvg(string word)
- {
- string
- current_lyb_word,
- svg_library = "cx cy rx ry r x1 x2 y1 y2 width height viewBox";
- char
- ch;
- for (int i = 0; i <= svg_library.length(); ++i)
- {
- ch = svg_library[i];
- if (ch != ' ' && i != svg_library.length())
- current_lyb_word += ch;
- else
- {
- if (word == current_lyb_word)
- return 1;
- current_lyb_word = "";
- }
- }
- return 0;
- }
- /* Меняет числа в атрибутах */
- string ChangeNumSvg(string word, float k)
- {
- string
- result,
- current_num;
- char
- ch;
- for (int i = 0; i <= word.length(); ++i)
- {
- ch = word[i];
- if (ch != ' ' && i != word.length())
- {
- current_num += ch;
- }
- else
- {
- current_num = ChangeNumber(current_num, k);
- result += (current_num + ' ');
- current_num = "";
- }
- }
- result += '\b';
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement