Commonize visualization support.
* src/abg-viz-svg.h: Move common code to... * src/abg-viz-dot.h: Move common code to... * src/abg-viz-common.h: ...here. New. * src/abg-viz-svg.cc: Move common code to... * src/abg-viz-common.cc: ...here. New. * src/Makefile.am: Add abg-viz-common.cc, abg-viz-common.h * src/Makefile.in: Regenerate.
This commit is contained in:
parent
f3dae517b9
commit
1807401e6c
|
@ -10,6 +10,7 @@ abg-hash.h \
|
|||
abg-writer.h \
|
||||
abg-config.h \
|
||||
abg-version.h \
|
||||
abg-viz-common.h \
|
||||
abg-viz-dot.h \
|
||||
abg-viz-svg.h
|
||||
|
||||
|
@ -21,6 +22,7 @@ abg-libxml-utils.cc \
|
|||
abg-hash.cc \
|
||||
abg-writer.cc \
|
||||
abg-config.cc \
|
||||
abg-viz-common.cc \
|
||||
abg-viz-dot.cc \
|
||||
abg-viz-svg.cc
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ libabigail_la_LIBADD =
|
|||
am__objects_1 =
|
||||
am_libabigail_la_OBJECTS = $(am__objects_1) abg-ir.lo abg-reader.lo \
|
||||
abg-corpus.lo abg-libxml-utils.lo abg-hash.lo abg-writer.lo \
|
||||
abg-config.lo abg-viz-dot.lo abg-viz-svg.lo
|
||||
abg-config.lo abg-viz-common.lo abg-viz-dot.lo abg-viz-svg.lo
|
||||
libabigail_la_OBJECTS = $(am_libabigail_la_OBJECTS)
|
||||
AM_V_lt = $(am__v_lt_@AM_V@)
|
||||
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
|
||||
|
@ -309,6 +309,7 @@ abg-hash.h \
|
|||
abg-writer.h \
|
||||
abg-config.h \
|
||||
abg-version.h \
|
||||
abg-viz-common.h \
|
||||
abg-viz-dot.h \
|
||||
abg-viz-svg.h
|
||||
|
||||
|
@ -320,6 +321,7 @@ abg-libxml-utils.cc \
|
|||
abg-hash.cc \
|
||||
abg-writer.cc \
|
||||
abg-config.cc \
|
||||
abg-viz-common.cc \
|
||||
abg-viz-dot.cc \
|
||||
abg-viz-svg.cc
|
||||
|
||||
|
@ -413,6 +415,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/abg-ir.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/abg-libxml-utils.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/abg-reader.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/abg-viz-common.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/abg-viz-dot.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/abg-viz-svg.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/abg-writer.Plo@am__quote@
|
||||
|
|
|
@ -0,0 +1,154 @@
|
|||
|
||||
// Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU Application Binary Interface Generic
|
||||
// Analysis and Instrumentation Library (libabigail). This library is
|
||||
// free software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the Free
|
||||
// Software Foundation; either version 3, or (at your option) any
|
||||
// later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
|
||||
// Under Section 7 of GPL version 3, you are granted additional
|
||||
// permissions described in the GCC Runtime Library Exception, version
|
||||
// 3.1, as published by the Free Software Foundation.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// and a copy of the GCC Runtime Library Exception along with this
|
||||
// program; see the files COPYING3 and COPYING.RUNTIME respectively.
|
||||
// If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// -*- mode: C++ -*-
|
||||
|
||||
#include "abg-viz-svg.h"
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
|
||||
namespace abigail
|
||||
{
|
||||
|
||||
using std::ostream;
|
||||
using std::ostringstream;
|
||||
|
||||
// Constants.
|
||||
|
||||
// Using pixels, units vs. representation
|
||||
// const canvas ansi_letter_mm = { units::millimeter, 215.9, 279.4 };
|
||||
// const canvas iso_a4_mm = { units::millimeter, 210, 297 };
|
||||
// const canvas ansi_letter_px = { units::pixel, 765, 990 };
|
||||
// const canvas iso_a4_px = { units::pixel, 765, 990 };
|
||||
const canvas ansi_letter_canvas = { units::pixel, 765, 990 };
|
||||
const canvas iso_a4_canvas = { units::pixel, 765, 990 };
|
||||
|
||||
const typography arial_typo = \
|
||||
{ "'ArialMT'", 12, color::black, R"(text-anchor="middle")"};
|
||||
|
||||
const typography source_code_pro_typo = \
|
||||
{ "Source Code Pro Light", 12, color::black, R"(text-anchor="middle")"};
|
||||
|
||||
const typography roboto_typo = \
|
||||
{ "Roboto Light", 12, color::black, R"(text-anchor="middle")"};
|
||||
|
||||
const row::style primary_row_sty = { color::white, color::black, "" };
|
||||
const row::style base_row_sty = { color::white, color::gray75, "" };
|
||||
const row::style member_row_sty = { color::black, color::gray25, "" };
|
||||
const row::style implementation_row_sty = { color::black, color::white, "" };
|
||||
|
||||
|
||||
// XXX Do not export.
|
||||
void
|
||||
string_replace(std::string& target, const std::string& match,
|
||||
const std::string& replace)
|
||||
{
|
||||
size_t pos = 0;
|
||||
while((pos = target.find(match, pos)) != std::string::npos)
|
||||
{
|
||||
target.replace(pos, match.length(), replace);
|
||||
pos += replace.length();
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
units_to_string(units __val)
|
||||
{
|
||||
std::string ret;
|
||||
switch (__val)
|
||||
{
|
||||
case units::millimeter:
|
||||
ret = "mm";
|
||||
break;
|
||||
case units::pixel:
|
||||
ret = "px";
|
||||
break;
|
||||
default:
|
||||
throw std::logic_error("abigail::units_to_string units not recognized");
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string
|
||||
color_to_string(color __val)
|
||||
{
|
||||
std::string ret;
|
||||
switch (__val)
|
||||
{
|
||||
case color::white:
|
||||
ret = "white";
|
||||
break;
|
||||
case color::gray25:
|
||||
ret = "gainsboro";
|
||||
break;
|
||||
case color::gray75:
|
||||
ret = "slategray";
|
||||
break;
|
||||
case color::black:
|
||||
ret = "black";
|
||||
break;
|
||||
default:
|
||||
throw std::logic_error("abigail::color_to_string color not recognized");
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string
|
||||
typography::anchor_to_string(anchor __val) const
|
||||
{
|
||||
std::string ret;
|
||||
switch (__val)
|
||||
{
|
||||
case start:
|
||||
ret = "start";
|
||||
break;
|
||||
case middle:
|
||||
ret = "middle";
|
||||
break;
|
||||
default:
|
||||
throw std::logic_error("abigail::anchor_to_string anchor not recognized");
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
typography::to_attribute(anchor __a) const
|
||||
{
|
||||
const std::string name("__name");
|
||||
const std::string size("__size");
|
||||
const std::string anchor("__anchor");
|
||||
std::string strip = R"(font-family="__name" font-size="__size" text-anchor="__anchor")";
|
||||
string_replace(strip, name, _M_face);
|
||||
string_replace(strip, size, std::to_string(_M_size));
|
||||
string_replace(strip, anchor, anchor_to_string(__a));
|
||||
|
||||
// NB: Add in extra _M_style if necessary.
|
||||
return strip;
|
||||
}
|
||||
|
||||
}//end namespace abigail
|
|
@ -0,0 +1,121 @@
|
|||
// Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU Application Binary Interface Generic
|
||||
// Analysis and Instrumentation Library (libabigail). This library is
|
||||
// free software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the Free
|
||||
// Software Foundation; either version 3, or (at your option) any
|
||||
// later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
|
||||
// Under Section 7 of GPL version 3, you are granted additional
|
||||
// permissions described in the GCC Runtime Library Exception, version
|
||||
// 3.1, as published by the Free Software Foundation.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// and a copy of the GCC Runtime Library Exception along with this
|
||||
// program; see the files COPYING3 and COPYING.RUNTIME respectively.
|
||||
// If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// -*- mode: C++ -*-
|
||||
/// @file
|
||||
|
||||
#ifndef __ABG_VIZ_COMMON_H__
|
||||
#define __ABG_VIZ_COMMON_H__
|
||||
|
||||
#include <sstream> //stringstream
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <array>
|
||||
|
||||
namespace abigail
|
||||
{
|
||||
|
||||
/// Measurement abstraction type, conversion function.
|
||||
enum class units
|
||||
{
|
||||
// NB: 1 pixel = .264583 mm
|
||||
millimeter, // mm
|
||||
pixel // px
|
||||
};
|
||||
|
||||
std::string
|
||||
units_to_string(units);
|
||||
|
||||
typedef unsigned short units_type;
|
||||
|
||||
|
||||
/// Color, conversion function.
|
||||
enum class color
|
||||
{
|
||||
white,
|
||||
gray25, // gainsboro
|
||||
gray75, // slategray
|
||||
black
|
||||
};
|
||||
|
||||
std::string
|
||||
color_to_string(color);
|
||||
|
||||
|
||||
/*
|
||||
Page/Canvas/Drawing area description.
|
||||
Size, origin location in 2D (x,y), heigh, width
|
||||
|
||||
ANSI Letter mm == (units::millimeter, 215.9, 279.4);
|
||||
ANSI Letter pixels == (units::pixel, 765, 990);
|
||||
ISO A4 mm == (units::millimeter, 210, 297);
|
||||
ISO A4 pixels == (units::pixel, 744.09, 1052.36);
|
||||
*/
|
||||
struct canvas
|
||||
{
|
||||
units _M_units;
|
||||
units_type _M_width;
|
||||
units_type _M_height;
|
||||
};
|
||||
|
||||
/// Useful canvas constants.
|
||||
extern const canvas ansi_letter_canvas;
|
||||
extern const canvas iso_a4_canvas;
|
||||
|
||||
|
||||
/*
|
||||
Character rendering, type, fonts, styles.
|
||||
|
||||
Expect to keep changing the output, so use this abstraction to set
|
||||
styling defaults, so that one can just assign types instead of doing
|
||||
a bunch of search-and-replace operations when changing type
|
||||
characteristics.
|
||||
*/
|
||||
struct typography
|
||||
{
|
||||
enum anchor { start, middle };
|
||||
|
||||
std::string _M_face; // System font name
|
||||
unsigned short _M_size; // Display size
|
||||
color _M_color;
|
||||
std::string _M_style; // Any other attributes
|
||||
|
||||
std::string
|
||||
to_attribute(anchor) const;
|
||||
|
||||
std::string
|
||||
anchor_to_string(anchor) const;
|
||||
};
|
||||
|
||||
/// Useful typography constants.
|
||||
extern const typography arial_typo;
|
||||
extern const typography source_code_pro_typo;
|
||||
extern const typography roboto_light_typo;
|
||||
|
||||
// Utility function, like regex_replace.
|
||||
void
|
||||
string_replace(std::string&, const std::string&, const std::string&);
|
||||
|
||||
}// end namespace abigail
|
||||
|
||||
#endif //__ABG_VIZ_COMMON_H__
|
|
@ -24,95 +24,14 @@
|
|||
// -*- mode: C++ -*-
|
||||
/// @file
|
||||
|
||||
#ifndef __ABG_VIZ_SVG_H__
|
||||
#define __ABG_VIZ_SVG_H__
|
||||
|
||||
#include <sstream> //stringstream
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <array>
|
||||
#ifndef __ABG_VIZ_DOT_H__
|
||||
#define __ABG_VIZ_DOT_H__
|
||||
|
||||
#include <abg-viz-common.h>
|
||||
|
||||
namespace abigail
|
||||
{
|
||||
|
||||
/// Measurement abstraction type, conversion function.
|
||||
enum class units
|
||||
{
|
||||
// NB: 1 pixel = .264583 mm
|
||||
millimeter, // mm
|
||||
pixel // px
|
||||
};
|
||||
|
||||
std::string
|
||||
units_to_string(units);
|
||||
|
||||
typedef unsigned short units_type;
|
||||
|
||||
|
||||
/// Color, conversion function.
|
||||
enum class color
|
||||
{
|
||||
white,
|
||||
gray25, // gainsboro
|
||||
gray75, // slategray
|
||||
black
|
||||
};
|
||||
|
||||
std::string
|
||||
color_to_string(color);
|
||||
|
||||
|
||||
/*
|
||||
Page/Canvas/Drawing area description.
|
||||
Size, origin location in 2D (x,y), heigh, width
|
||||
|
||||
ANSI Letter mm == (units::millimeter, 215.9, 279.4);
|
||||
ANSI Letter pixels == (units::pixel, 765, 990);
|
||||
ISO A4 mm == (units::millimeter, 210, 297);
|
||||
ISO A4 pixels == (units::pixel, 744.09, 1052.36);
|
||||
*/
|
||||
struct canvas
|
||||
{
|
||||
units _M_units;
|
||||
units_type _M_width;
|
||||
units_type _M_height;
|
||||
};
|
||||
|
||||
/// Useful canvas constants.
|
||||
extern const canvas ansi_letter_canvas;
|
||||
extern const canvas iso_a4_canvas;
|
||||
|
||||
|
||||
/*
|
||||
Character rendering, type, fonts, styles.
|
||||
|
||||
Expect to keep changing the output, so use this abstraction to set
|
||||
styling defaults, so that one can just assign types instead of doing
|
||||
a bunch of search-and-replace operations when changing type
|
||||
characteristics.
|
||||
*/
|
||||
struct typography
|
||||
{
|
||||
enum anchor { start, middle };
|
||||
|
||||
std::string _M_face; // System font name
|
||||
unsigned short _M_size; // Display size
|
||||
color _M_color;
|
||||
std::string _M_style; // Any other attributes
|
||||
|
||||
std::string
|
||||
to_attribute(anchor) const;
|
||||
|
||||
std::string
|
||||
anchor_to_string(anchor) const;
|
||||
};
|
||||
|
||||
/// Useful typography constants.
|
||||
extern const typography arial_typo;
|
||||
extern const typography source_code_pro_typo;
|
||||
extern const typography roboto_light_typo;
|
||||
|
||||
/// Base class for graph nodes.
|
||||
struct node_base
|
||||
{ };
|
||||
|
|
|
@ -31,127 +31,6 @@
|
|||
namespace abigail
|
||||
{
|
||||
|
||||
using std::ostream;
|
||||
using std::ostringstream;
|
||||
|
||||
// Constants.
|
||||
|
||||
// Using pixels, units vs. representation
|
||||
// const canvas ansi_letter_mm = { units::millimeter, 215.9, 279.4 };
|
||||
// const canvas iso_a4_mm = { units::millimeter, 210, 297 };
|
||||
// const canvas ansi_letter_px = { units::pixel, 765, 990 };
|
||||
// const canvas iso_a4_px = { units::pixel, 765, 990 };
|
||||
const canvas ansi_letter_canvas = { units::pixel, 765, 990 };
|
||||
const canvas iso_a4_canvas = { units::pixel, 765, 990 };
|
||||
|
||||
const typography arial_typo = \
|
||||
{ "'ArialMT'", 12, color::black, R"(text-anchor="middle")"};
|
||||
|
||||
const typography source_code_pro_typo = \
|
||||
{ "Source Code Pro Light", 12, color::black, R"(text-anchor="middle")"};
|
||||
|
||||
const typography roboto_typo = \
|
||||
{ "Roboto Light", 12, color::black, R"(text-anchor="middle")"};
|
||||
|
||||
const row::style primary_row_sty = { color::white, color::black, "" };
|
||||
const row::style base_row_sty = { color::white, color::gray75, "" };
|
||||
const row::style member_row_sty = { color::black, color::gray25, "" };
|
||||
const row::style implementation_row_sty = { color::black, color::white, "" };
|
||||
|
||||
|
||||
// Utility function, like regex_replace.
|
||||
void
|
||||
string_replace(std::string& target, const std::string& match,
|
||||
const std::string& replace)
|
||||
{
|
||||
size_t pos = 0;
|
||||
while((pos = target.find(match, pos)) != std::string::npos)
|
||||
{
|
||||
target.replace(pos, match.length(), replace);
|
||||
pos += replace.length();
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
units_to_string(units __val)
|
||||
{
|
||||
std::string ret;
|
||||
switch (__val)
|
||||
{
|
||||
case units::millimeter:
|
||||
ret = "mm";
|
||||
break;
|
||||
case units::pixel:
|
||||
ret = "px";
|
||||
break;
|
||||
default:
|
||||
throw std::logic_error("abigail::units_to_string units not recognized");
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string
|
||||
color_to_string(color __val)
|
||||
{
|
||||
std::string ret;
|
||||
switch (__val)
|
||||
{
|
||||
case color::white:
|
||||
ret = "white";
|
||||
break;
|
||||
case color::gray25:
|
||||
ret = "gainsboro";
|
||||
break;
|
||||
case color::gray75:
|
||||
ret = "slategray";
|
||||
break;
|
||||
case color::black:
|
||||
ret = "black";
|
||||
break;
|
||||
default:
|
||||
throw std::logic_error("abigail::color_to_string color not recognized");
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string
|
||||
typography::anchor_to_string(anchor __val) const
|
||||
{
|
||||
std::string ret;
|
||||
switch (__val)
|
||||
{
|
||||
case start:
|
||||
ret = "start";
|
||||
break;
|
||||
case middle:
|
||||
ret = "middle";
|
||||
break;
|
||||
default:
|
||||
throw std::logic_error("abigail::anchor_to_string anchor not recognized");
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
typography::to_attribute(anchor __a) const
|
||||
{
|
||||
const std::string name("__name");
|
||||
const std::string size("__size");
|
||||
const std::string anchor("__anchor");
|
||||
std::string strip = R"(font-family="__name" font-size="__size" text-anchor="__anchor")";
|
||||
string_replace(strip, name, _M_face);
|
||||
string_replace(strip, size, std::to_string(_M_size));
|
||||
string_replace(strip, anchor, anchor_to_string(__a));
|
||||
|
||||
// NB: Add in extra _M_style if necessary.
|
||||
return strip;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
svg::write()
|
||||
{
|
||||
|
|
|
@ -27,93 +27,11 @@
|
|||
#ifndef __ABG_VIZ_SVG_H__
|
||||
#define __ABG_VIZ_SVG_H__
|
||||
|
||||
#include <sstream> //stringstream
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <array>
|
||||
|
||||
#include <abg-viz-common.h>
|
||||
|
||||
namespace abigail
|
||||
{
|
||||
|
||||
/// Measurement abstraction type, conversion function.
|
||||
enum class units
|
||||
{
|
||||
// NB: 1 pixel = .264583 mm
|
||||
millimeter, // mm
|
||||
pixel // px
|
||||
};
|
||||
|
||||
std::string
|
||||
units_to_string(units);
|
||||
|
||||
typedef unsigned short units_type;
|
||||
|
||||
|
||||
/// Color, conversion function.
|
||||
enum class color
|
||||
{
|
||||
white,
|
||||
gray25, // gainsboro
|
||||
gray75, // slategray
|
||||
black
|
||||
};
|
||||
|
||||
std::string
|
||||
color_to_string(color);
|
||||
|
||||
|
||||
/*
|
||||
Page/Canvas/Drawing area description.
|
||||
Size, origin location in 2D (x,y), heigh, width
|
||||
|
||||
ANSI Letter mm == (units::millimeter, 215.9, 279.4);
|
||||
ANSI Letter pixels == (units::pixel, 765, 990);
|
||||
ISO A4 mm == (units::millimeter, 210, 297);
|
||||
ISO A4 pixels == (units::pixel, 744.09, 1052.36);
|
||||
*/
|
||||
struct canvas
|
||||
{
|
||||
units _M_units;
|
||||
units_type _M_width;
|
||||
units_type _M_height;
|
||||
};
|
||||
|
||||
/// Useful canvas constants.
|
||||
extern const canvas ansi_letter_canvas;
|
||||
extern const canvas iso_a4_canvas;
|
||||
|
||||
|
||||
/*
|
||||
Character rendering, type, fonts, styles.
|
||||
|
||||
Expect to keep changing the output, so use this abstraction to set
|
||||
styling defaults, so that one can just assign types instead of doing
|
||||
a bunch of search-and-replace operations when changing type
|
||||
characteristics.
|
||||
*/
|
||||
struct typography
|
||||
{
|
||||
enum anchor { start, middle };
|
||||
|
||||
std::string _M_face; // System font name
|
||||
unsigned short _M_size; // Display size
|
||||
color _M_color;
|
||||
std::string _M_style; // Any other attributes
|
||||
|
||||
std::string
|
||||
to_attribute(anchor) const;
|
||||
|
||||
std::string
|
||||
anchor_to_string(anchor) const;
|
||||
};
|
||||
|
||||
/// Useful typography constants.
|
||||
extern const typography arial_typo;
|
||||
extern const typography source_code_pro_typo;
|
||||
extern const typography roboto_light_typo;
|
||||
|
||||
|
||||
/*
|
||||
Row displaying one element of member data.
|
||||
|
||||
|
|
Loading…
Reference in New Issue