The Character Style and XML short element inset.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8078 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Martin Vermeer 2003-11-12 14:38:26 +00:00
parent b171a9b6fb
commit 59fefa0759
23 changed files with 971 additions and 124 deletions

View File

@ -1,3 +1,12 @@
2003-11-12 Martin Vermeer <martin.vermeer@hut.fi>
* lib/examples/docbook_article.lyx:
* lib/layouts/db_stdclass.inc:
* lib/layouts/stdclass.inc:
* lib/ui/stdmenus.ui: The Character Style /XML short
element patch.
2003-11-07 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* Makefile.am (install-xfonts):

View File

@ -1,12 +1,12 @@
#LyX 1.3 created this file. For more info see http://www.lyx.org/
\lyxformat 221
#LyX 1.4.0cvs created this file. For more info see http://www.lyx.org/
\lyxformat 225
\textclass docbook
\language english
\inputencoding default
\fontscheme default
\graphics default
\paperfontsize default
\spacing single
\spacing single
\papersize Default
\paperpackage a4
\use_geometry 0
@ -23,83 +23,140 @@
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes 0
\end_header
\layout SGML
\begin_layout SGML
\begin_inset Note
collapsed true
\layout Standard
\begin_layout Standard
Here goes the information about the article:
\layout Standard
\end_layout
\begin_layout Standard
* title
\layout Standard
\end_layout
\begin_layout Standard
* date
\layout Standard
\end_layout
\begin_layout Standard
* author
\layout Standard
\end_layout
\begin_layout Standard
+ first name
\layout Standard
\end_layout
\begin_layout Standard
+ last name
\layout Standard
\end_layout
\begin_layout Standard
* abstract
\end_layout
\end_inset
\layout Title
\end_layout
\begin_layout Title
\added_space_top vfill \added_space_bottom vfill
Docbook with LyX
\layout Date
\end_layout
\begin_layout Date
24 September 1999
\layout Author
\end_layout
\begin_layout Author
\end_layout
\begin_deeper
\layout SGML
\begin_layout SGML
\align center
\size normal
\begin_inset Note
collapsed true
\layout Standard
\begin_layout Standard
The author name is always composed of:
\layout Standard
\end_layout
\begin_layout Standard
* first name
\layout Standard
\end_layout
\begin_layout Standard
* surname
\layout Standard
\end_layout
\begin_layout Standard
It is always possible to have more than one author.
\end_layout
\end_inset
\layout FirstName
\end_layout
\end_deeper
\begin_layout Author
\begin_inset FirstName
collapsed true
\begin_layout Standard
Jose'
\layout Surname
\end_layout
\end_inset
\begin_inset Surname
collapsed true
\begin_layout Standard
Matos
\end_deeper
\layout Abstract
\end_layout
\end_inset
\end_layout
\begin_layout Abstract
This is a small illustration of lyx's features using DocBook.
\layout Abstract
\end_layout
\begin_layout Abstract
The abstract can span several paragraphs.
\layout Section
\end_layout
\begin_layout Section
\begin_inset LatexCommand \label{first-section}
@ -107,20 +164,30 @@ The abstract can span several paragraphs.
\end_inset
Introduction
\layout Standard
\end_layout
\begin_layout Standard
This file ilustrates the generation of docbook documents with LyX.
\layout Standard
\end_layout
\begin_layout Standard
This will improve as soon as new features are available.
\layout Section
\end_layout
\begin_layout Section
Standard layouts
\layout Standard
\end_layout
\begin_layout Standard
One of the goals is the support, as much as possible, of layouts used in
other textclass, for compatibility purposes.
\layout Standard
\end_layout
\begin_layout Standard
Remember that this is work in progress, I would like to hear any comments,
good or
@ -132,65 +199,103 @@ bad
\end_inset
.
\layout Subsection
\end_layout
\begin_layout Subsection
Lists
\layout Standard
\end_layout
\begin_layout Standard
This is an example with several nested lists.
\layout Itemize
\end_layout
\begin_layout Itemize
item 1
\end_layout
\begin_deeper
\layout Enumerate
\begin_layout Enumerate
item 2
\layout Description
\end_layout
\begin_layout Description
new item
\end_layout
\begin_deeper
\layout Enumerate
\begin_layout Enumerate
collection
\end_layout
\end_deeper
\end_deeper
\layout Itemize
\begin_layout Itemize
new set
\layout Subsection
\end_layout
\begin_layout Subsection
Code
\layout Standard
\end_layout
\begin_layout Standard
Required steps to have a running lyx.
\layout Quotation
\end_layout
\begin_layout Quotation
Be carefull with your own code.
\layout Quotation
\end_layout
\begin_layout Quotation
The debugger.
\layout Code
\end_layout
\begin_layout Code
cat > env.out
\layout Code
\end_layout
\begin_layout Code
tar xvzf lyx.tgz
\layout Code
\end_layout
\begin_layout Code
cd lyx-1_0_x
\layout Code
\end_layout
\begin_layout Code
./configure
\layout Code
\end_layout
\begin_layout Code
make
\layout Code
\end_layout
\begin_layout Code
make install
\layout Subsection
\end_layout
\begin_layout Subsection
Labels
\layout Standard
\end_layout
\begin_layout Standard
If a label is the first element in any layout, that label will be merged
with that element.
@ -200,41 +305,56 @@ If a label is the first element in any layout, that label will be merged
\end_inset
.
\layout Subsection
\end_layout
\begin_layout Subsection
Fonts
\layout Standard
\end_layout
\begin_layout Standard
The only fonts supported are
\emph on
Emphasis
\emph default
and
\begin_inset ERT
status Collapsed
\begin_inset Literal
collapsed true
\begin_layout Standard
SGML
\end_layout
\layout Standard
<literal>SGML</literal>
\end_inset
.
\layout Subsection
\end_layout
\begin_layout Subsection
Figures
\layout Standard
\end_layout
\begin_layout Standard
One of the major changes in the docbook when compared with the linuxdoc
support are the figures support.
LyX only allows to view eps figures.
So you should have one of these if you want to take advantage of this feature.
\layout Standard
\end_layout
\begin_layout Standard
Notice that when the docbook code is exported the filename extension is
stripped.
This enables that when the several backends are processed in sgmltools,
the corresponding extensions are added.
The default extension are eps for the print and gif for the html backend.
\layout Standard
\end_layout
\begin_layout Standard
\begin_inset Float figure
@ -242,7 +362,7 @@ placement htbp
wide false
collapsed false
\layout Standard
\begin_layout Standard
\begin_inset Graphics
@ -252,19 +372,28 @@ collapsed false
height 3cm
rotateAngle 45
rotateOrigin center
\end_inset
\layout Caption
\end_layout
\begin_layout Caption
Nice platypus
\end_layout
\end_inset
\layout Standard
\end_layout
\begin_layout Standard
Wide figures are treated as normal figures.
\layout Standard
\end_layout
\begin_layout Standard
\begin_inset Float figure
@ -272,7 +401,7 @@ placement htbp
wide true
collapsed false
\layout Standard
\begin_layout Standard
\begin_inset Graphics
@ -282,20 +411,29 @@ collapsed false
height 3cm
rotateAngle 45
rotateOrigin center
\end_inset
\layout Caption
\end_layout
\begin_layout Caption
long, very long...
:-)
\end_layout
\end_inset
\layout Subsection
\end_layout
\begin_layout Subsection
Tables
\layout Standard
\end_layout
\begin_layout Standard
There is also basic support for tables.
\begin_inset Float table
@ -303,10 +441,10 @@ placement htbp
wide false
collapsed false
\layout Standard
\begin_layout Standard
\added_space_top 0.3cm \added_space_bottom 0.3cm \align center
\begin_inset Tabular
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="5">
<features>
<column alignment="center" valignment="top" leftline="true" width="0pt">
@ -318,40 +456,50 @@ collapsed false
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
Software 1
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
Software 2
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
Software 3
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
Software 4
\end_layout
\end_inset
</cell>
</row>
@ -359,39 +507,49 @@ Software 4
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
Plataform 1
\end_layout
\end_inset
</cell>
<cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
25 MB
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
10 MB
\end_layout
\end_inset
</cell>
<cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
34 MB
\end_layout
\end_inset
</cell>
<cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
\end_layout
\end_inset
</cell>
@ -400,40 +558,50 @@ Plataform 1
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
Plataform 2
\end_layout
\end_inset
</cell>
<cell multicolumn="1" alignment="center" valignment="top" bottomline="true" leftline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
12 MB
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
30 MB
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text
\layout Standard
\begin_layout Standard
35 MB
\end_layout
\end_inset
</cell>
</row>
@ -442,19 +610,29 @@ Plataform 2
\end_inset
\layout Caption
\end_layout
\begin_layout Caption
Nice Formal Table
\end_layout
\end_inset
\layout Standard
\end_layout
\begin_layout Standard
As it happens with the figures the wide tables are treated as normal tables.
\layout Subsection
\end_layout
\begin_layout Subsection
Margins
\layout Standard
\end_layout
\begin_layout Standard
There are some restrictions when using margins.
For further information on docbook allowed syntax consult the
@ -463,128 +641,188 @@ There are some restrictions when using margins.
\end_inset
.
\layout Quotation
\end_layout
\begin_layout Quotation
It is also possible to insert margin notes inside some environments.
\end_layout
\begin_deeper
\layout SGML
\begin_layout SGML
\begin_inset Marginal
collapsed true
\layout Standard
\begin_layout Standard
margin note
\layout Standard
\end_layout
\begin_layout Standard
second par -> margin note
\layout Standard
\end_layout
\begin_layout Standard
third par -> margin note
\end_layout
\end_inset
\end_layout
\end_deeper
\layout Quotation
\begin_layout Quotation
Notice that the previous layout is at level 1
\begin_inset Foot
collapsed true
\layout Standard
\begin_layout Standard
This comes from a docbook restriction.
Sidebar can only appear inside "MSGTEXT", "CAUTION", "IMPORTANT", "NOTE",
"TIP", "WARNING", "BLOCKQUOTE".
\layout Standard
\end_layout
\begin_layout Standard
These environments are easily added to the docbook layout.
\end_layout
\end_inset
and so is the follow:
\end_layout
\begin_deeper
\layout SGML
\begin_layout SGML
\begin_inset Marginal
collapsed true
\layout Standard
\begin_layout Standard
too marginal ;-)
\end_layout
\end_inset
\end_layout
\end_deeper
\layout Section
\begin_layout Section
The road map
\layout Standard
\end_layout
\begin_layout Standard
This is a small list of the remaining tasks:
\layout Itemize
\end_layout
\begin_layout Itemize
Expand the number of layouts
\end_layout
\begin_deeper
\layout Itemize
\begin_layout Itemize
example
\layout Itemize
\end_layout
\begin_layout Itemize
note
\layout Itemize
\end_layout
\begin_layout Itemize
warning
\layout Itemize
\end_layout
\begin_layout Itemize
tip
\layout Itemize
\end_layout
\begin_layout Itemize
caution
\layout Itemize
\end_layout
\begin_layout Itemize
important
\end_layout
\end_deeper
\layout Itemize
\begin_layout Itemize
Compose other layout files, besides article
\end_layout
\begin_deeper
\layout Enumerate
\begin_layout Enumerate
book
\layout Enumerate
\end_layout
\begin_layout Enumerate
set (very unlikely)
\begin_inset Foot
collapsed true
\layout Standard
\begin_layout Standard
I do not expect lyx to deal with colection of books, for now!
\end_layout
\end_inset
\layout Enumerate
\end_layout
\begin_layout Enumerate
refentry
\end_layout
\end_deeper
\layout Itemize
\begin_layout Itemize
goodies
\end_layout
\begin_deeper
\layout Enumerate
\begin_layout Enumerate
including other lyx files
\layout Enumerate
\end_layout
\begin_layout Enumerate
more advanced tables support
\end_layout
\end_deeper
\layout Itemize
\begin_layout Itemize
better documentation
\layout Standard
\end_layout
\begin_layout Standard
That's all.
;-)
\the_end
\end_layout
\end_document

View File

@ -26,6 +26,55 @@ Style Standard
End
CharStyle Filename
LatexType Command
LatexName filename
Font
Family Typewriter
EndFont
LabelFont
Shape Italic
Color red
EndFont
End
CharStyle FirstName
LatexType Command
LatexName firstname
Font
Shape SmallCaps
EndFont
LabelFont
Shape Italic
Color red
EndFont
End
CharStyle Surname
LatexType Command
LatexName surname
Font
Shape SmallCaps
EndFont
LabelFont
Shape Italic
Color red
EndFont
End
CharStyle Literal
LatexType Command
LatexName literal
Font
Family Typewriter
EndFont
LabelFont
Shape Italic
Color red
EndFont
End
Input db_stdlists.inc
Input db_stdsections.inc
Input db_stdstarsections.inc

View File

@ -35,6 +35,21 @@ Style Standard
LabelType No_Label
End
CharStyle Noun
LatexType Command
LatexName noun
Font
Shape SmallCaps
EndFont
LabelFont
Shape SmallCaps
Color blue
EndFont
Preamble
\newcommand{\noun}[1]{\textsc{#1}}
EndPreamble
End
Input stdlists.inc
Input stdsections.inc

View File

@ -231,6 +231,7 @@ Menuset
Submenu "Note|N" "insert_note"
Submenu "Box" "insert_box"
Submenu "Branch|B" "branches"
Submenu "Character Style" "charstyle"
Submenu "File|e" "insert_file"
Separator
Item "Citation Reference...|C" "dialog-show-new-inset citation"
@ -354,6 +355,10 @@ Menuset
Branches
End
Menu "charstyle"
CharStyles
End
#
# DOCUMENT MENU
#

View File

@ -151,6 +151,7 @@ src/insets/insetbibtex.C
src/insets/insetbox.C
src/insets/insetbranch.C
src/insets/insetcaption.C
src/insets/insetelement.C
src/insets/insetenv.C
src/insets/insetert.C
src/insets/insetexternal.C
@ -198,6 +199,7 @@ src/output_plaintext.C
src/paragraph.C
src/paragraph_funcs.C
src/rowpainter.C
src/support/path_defines.C
src/text.C
src/text2.C
src/text3.C

View File

@ -1,3 +1,19 @@
2003-11-12 Martin Vermeer <martin.vermeer@hut.fi>
* src/LaTeXFeatures.C:
* src/LyXAction.C:
* src/MenuBackend.C:
* src/MenuBackend.h:
* src/dispatchresult.h:
* src/factory.C:
* src/lfuns.h:
* src/lyxfunc.C:
* src/lyxtextclass.C:
* src/lyxtextclass.h:
* src/text3.C: The Character Style /XML short
element patch.
2003-11-11 Martin Vermeer <martin.vermeer@hut.fi>
* text3.C:

View File

@ -409,6 +409,13 @@ string const LaTeXFeatures::getTClassPreamble() const
tcpreamble << tclass[*cit]->preamble();
}
CharStyles::iterator cs = tclass.charstyles().begin();
CharStyles::iterator csend = tclass.charstyles().end();
for (; cs != csend; ++cs) {
if (isRequired(cs->name))
tcpreamble << cs->preamble;
}
return tcpreamble.str();
}

View File

@ -226,6 +226,7 @@ void LyXAction::init()
{ LFUN_META_FAKE, "meta-prefix", NoBuffer },
{ LFUN_INSET_MINIPAGE, "minipage-insert", Noop },
{ LFUN_INSERT_BRANCH, "branch-insert", Noop },
{ LFUN_INSERT_CHARSTYLE, "charstyle-insert", Noop },
{ LFUN_INSERT_NOTE, "note-insert", Noop },
{ LFUN_INSERT_BOX, "box-insert", Noop },
{ LFUN_GOTONOTE, "note-next", ReadOnly },

View File

@ -191,6 +191,7 @@ Menu & Menu::read(LyXLex & lex)
md_item = 1,
md_branches,
md_documents,
md_charstyles,
md_endmenu,
md_exportformats,
md_importformats,
@ -210,6 +211,7 @@ Menu & Menu::read(LyXLex & lex)
struct keyword_item menutags[md_last - 1] = {
{ "branches", md_branches },
{ "charstyles", md_charstyles },
{ "documents", md_documents },
{ "end", md_endmenu },
{ "exportformats", md_exportformats },
@ -259,6 +261,10 @@ Menu & Menu::read(LyXLex & lex)
add(MenuItem(MenuItem::Lastfiles));
break;
case md_charstyles:
add(MenuItem(MenuItem::CharStyles));
break;
case md_documents:
add(MenuItem(MenuItem::Documents));
break;
@ -524,6 +530,28 @@ void expandFloatInsert(Menu & tomenu, LyXView const * view)
}
void expandCharStyleInsert(Menu & tomenu, LyXView const * view)
{
if (!view->buffer()) {
tomenu.add(MenuItem(MenuItem::Command,
_("No Documents Open!"),
FuncRequest(LFUN_NOACTION)),
view);
return;
}
CharStyles & charstyles =
view->buffer()->params().getLyXTextClass().charstyles();
CharStyles::iterator cit = charstyles.begin();
CharStyles::iterator end = charstyles.end();
for (; cit != end; ++cit) {
string const label = cit->name;
tomenu.add(MenuItem(MenuItem::Command, label,
FuncRequest(LFUN_INSERT_CHARSTYLE,
cit->name)), view);
}
}
Menu::size_type const max_number_of_items = 25;
void expandToc2(Menu & tomenu,
@ -691,6 +719,10 @@ void MenuBackend::expand(Menu const & frommenu, Menu & tomenu,
expandFormats(cit->kind(), tomenu, view);
break;
case MenuItem::CharStyles:
expandCharStyleInsert(tomenu, view);
break;
case MenuItem::FloatListInsert:
expandFloatListInsert(tomenu, view);
break;

View File

@ -55,6 +55,9 @@ public:
/** This is a list of importable formats
typically for the File->Export menu. */
ImportFormats,
/** This is the list of elements available
* for insertion into document. */
CharStyles,
/** This is the list of floats that we can
insert a list for. */
FloatListInsert,

View File

@ -27,7 +27,7 @@
the inset.
FINISHED_POP = FINISHED, but move the cursor out the inset
(possibly more than one level)
UNDISPATCHED = the action was not catched, it should be
UNDISPATCHED = the action was not caught, it should be
dispatched by lower level insets
*/
enum dispatch_result_t {

View File

@ -26,6 +26,7 @@
#include "insets/insetbibtex.h"
#include "insets/insetcaption.h"
#include "insets/insetcite.h"
#include "insets/insetcharstyle.h"
#include "insets/insetenv.h"
#include "insets/insetert.h"
#include "insets/insetexternal.h"
@ -86,6 +87,12 @@ InsetOld * createInset(FuncRequest const & cmd)
case LFUN_INSET_MINIPAGE:
return new InsetMinipage(params);
case LFUN_INSERT_CHARSTYLE: {
string s = cmd.getArg(0);
CharStyles::iterator found_cs = params.getLyXTextClass().charstyle(s);
return new InsetCharStyle(params, found_cs);
}
case LFUN_INSERT_NOTE: {
string arg = cmd.getArg(0);
if (arg.empty())
@ -335,8 +342,13 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf)
auto_ptr<InsetOld> inset;
LyXTextClass tclass = buf.params().getLyXTextClass();
lex.next();
string const tmptok = lex.getString();
string tmptok = lex.getString();
CharStyles::iterator found_cs = tclass.charstyle(tmptok);
if (found_cs != tclass.charstyles().end())
tmptok = "CharStyle";
// test the different insets
if (tmptok == "LatexCommand") {
@ -408,6 +420,8 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf)
|| tmptok == "Shadowbox" || tmptok == "Doublebox"
|| tmptok == "Ovalbox" || tmptok == "Frameless") {
inset.reset(new InsetBox(buf.params(), tmptok));
} else if (tmptok == "CharStyle") {
inset.reset(new InsetCharStyle(buf.params(), found_cs));
} else if (tmptok == "Branch") {
inset.reset(new InsetBranch(buf.params(), string()));
} else if (tmptok == "Include") {

View File

@ -1,3 +1,11 @@
2003-11-12 Martin Vermeer <martin.vermeer@hut.fi>
* src/insets/Makefile.am:
* src/insets/inset.h:
* src/insets/insetcharstyle.C:
* src/insets/insetcharstyle.h: The Character Style /XML short
element patch.
2003-11-11 Alfredo Braunstein <abraunst@lyx.org>
* insettext.C: remove all update calls

View File

@ -40,6 +40,8 @@ libinsets_la_SOURCES = \
insetbranch.h \
insetcaption.C \
insetcaption.h \
insetcharstyle.C \
insetcharstyle.h \
insetcite.C \
insetcite.h \
insetcollapsable.C \

View File

@ -134,7 +134,9 @@ public:
///
BRANCH_CODE, // 40
///
BOX_CODE
BOX_CODE,
///
CHARSTYLE_CODE
};
///

215
src/insets/insetcharstyle.C Normal file
View File

@ -0,0 +1,215 @@
/**
* \file insetcharstyle.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
* \author Martin Vermeer
* \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "insetcharstyle.h"
#include "BufferView.h"
#include "dispatchresult.h"
#include "funcrequest.h"
#include "gettext.h"
#include "LaTeXFeatures.h"
#include "LColor.h"
#include "lyxlex.h"
#include "lyxtext.h"
#include "metricsinfo.h"
#include "paragraph.h"
#include "support/std_sstream.h"
using std::string;
using std::auto_ptr;
using std::istringstream;
using std::ostream;
using std::ostringstream;
void InsetCharStyle::init()
{
setInsetName("CharStyle");
setButtonLabel();
}
InsetCharStyle::InsetCharStyle(BufferParams const & bp,
CharStyles::iterator cs)
: InsetCollapsable(bp)
{
params_.type = cs->name;
params_.latextype = cs->latextype;
params_.latexname = cs->latexname;
params_.font = cs->font;
params_.labelfont = cs->labelfont;
init();
}
InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
: InsetCollapsable(in), params_(in.params_)
{
init();
}
auto_ptr<InsetBase> InsetCharStyle::clone() const
{
return auto_ptr<InsetBase>(new InsetCharStyle(*this));
}
string const InsetCharStyle::editMessage() const
{
return _("Opened CharStyle Inset");
}
void InsetCharStyle::write(Buffer const & buf, ostream & os) const
{
params_.write(os);
InsetCollapsable::write(buf, os);
}
void InsetCharStyle::read(Buffer const & buf, LyXLex & lex)
{
InsetCollapsable::read(buf, lex);
setButtonLabel();
}
void InsetCharStyle::setButtonLabel()
{
LyXFont font(params_.labelfont);
font.realize(LyXFont(LyXFont::ALL_SANE));
font.decSize();
setLabel("Style: " + params_.type);
setLabelFont(font);
}
void InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
{
InsetCollapsable::metrics(mi, dim);
dim_ = dim;
}
void InsetCharStyle::getDrawFont(LyXFont & font) const
{
font = params_.font;
}
DispatchResult
InsetCharStyle::priv_dispatch(FuncRequest const & cmd,
idx_type & idx, pos_type & pos)
{
DispatchResult dr = InsetCollapsable::priv_dispatch(cmd, idx, pos);
setButtonLabel();
return dr;
}
namespace {
int outputVerbatim(std::ostream & os, InsetText inset)
{
int lines = 0;
ParagraphList::iterator par = inset.paragraphs.begin();
ParagraphList::iterator end = inset.paragraphs.end();
while (par != end) {
lyx::pos_type siz = par->size();
for (lyx::pos_type i = 0; i < siz; ++i) {
if (par->isNewline(i)) {
os << '\n';
++lines;
} else {
os << par->getChar(i);
}
}
++par;
if (par != end) {
os << "\n";
lines ++;
}
}
return lines;
}
} // namespace anon
int InsetCharStyle::latex(Buffer const & buf, ostream & os,
OutputParams const & runparams) const
{
os << "%\n\\" << params_.latexname << "{";
int i = outputVerbatim(os, inset);
os << "}%\n";
i += 2;
return i;
}
int InsetCharStyle::linuxdoc(Buffer const & buf, std::ostream & os,
OutputParams const & runparams) const
{
os << "<" << params_.latexname << ">";
int const i = outputVerbatim(os, inset);
os << "</" << params_.latexname << ">";
return i;
}
int InsetCharStyle::docbook(Buffer const & buf, std::ostream & os,
OutputParams const & runparams) const
{
os << "<" << params_.latexname << ">";
int const i = outputVerbatim(os, inset);
os << "</" << params_.latexname << ">";
return i;
}
int InsetCharStyle::plaintext(Buffer const & buf, std::ostream & os,
OutputParams const & runparams) const
{
return outputVerbatim(os, inset);
}
void InsetCharStyle::validate(LaTeXFeatures & features) const
{
features.require(params_.type);
}
void InsetCharStyleParams::write(ostream & os) const
{
os << type << "\n";
}
void InsetCharStyleParams::read(LyXLex & lex)
{
if (lex.isOK()) {
lex.next();
string token = lex.getString();
}
if (lex.isOK()) {
lex.next();
type = lex.getString();
}
}

View File

@ -0,0 +1,99 @@
// -*- C++ -*-
/**
* \file insetcharstyle.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
* \author Martin Vermeer
*
* Full author contact details are available in file CREDITS.
*/
#ifndef INSETCHARSTYLE_H
#define INSETCHARSTYLE_H
#include "insetcollapsable.h"
#include "lyxtextclass.h"
struct InsetCharStyleParams {
///
void write(std::ostream & os) const;
///
void read(LyXLex & lex);
///
std::string type;
///
std::string latextype;
///
std::string latexname;
///
LyXFont font;
///
LyXFont labelfont;
};
/** The CharStyle inset, also XML short element
*/
class InsetCharStyle : public InsetCollapsable {
public:
///
InsetCharStyle(BufferParams const &, CharStyles::iterator);
/// Copy constructor
InsetCharStyle(InsetCharStyle const &);
///
virtual std::auto_ptr<InsetBase> clone() const;
///
std::string const editMessage() const;
///
InsetOld::Code lyxCode() const { return InsetOld::CHARSTYLE_CODE; }
///
void write(Buffer const &, std::ostream &) const;
///
void read(Buffer const & buf, LyXLex & lex);
///
void setButtonLabel();
///
void metrics(MetricsInfo &, Dimension &) const;
///
void getDrawFont(LyXFont &) const;
///
int latex(Buffer const &, std::ostream &,
OutputParams const &) const;
///
int linuxdoc(Buffer const &, std::ostream &,
OutputParams const &) const;
///
int docbook(Buffer const &, std::ostream &,
OutputParams const &) const;
///
int plaintext(Buffer const &, std::ostream &,
OutputParams const &) const;
///
void validate(LaTeXFeatures &) const;
///
InsetCharStyleParams const & params() const { return params_; }
protected:
///
virtual
DispatchResult
priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
private:
friend class InsetCharStyleParams;
/// used by the constructors
void init();
///
InsetCharStyleParams params_;
};
#endif

View File

@ -331,6 +331,7 @@ enum kb_action {
LFUN_FINISHED_RIGHT,
LFUN_FINISHED_UP,
LFUN_FINISHED_DOWN,
LFUN_INSERT_CHARSTYLE,
LFUN_LASTACTION // end of the table
};

View File

@ -645,6 +645,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
case LFUN_INSERT_NOTE:
code = InsetOld::NOTE_CODE;
break;
case LFUN_INSERT_CHARSTYLE:
code = InsetOld::CHARSTYLE_CODE;
if (buf->params().getLyXTextClass().charstyles().empty())
disable = true;
break;
case LFUN_INSERT_BOX:
code = InsetOld::BOX_CODE;
break;

View File

@ -104,6 +104,7 @@ enum TextClassTags {
TC_INPUT,
TC_STYLE,
TC_DEFAULTSTYLE,
TC_CHARSTYLE,
TC_ENVIRONMENT,
TC_NOSTYLE,
TC_COLUMNS,
@ -131,6 +132,7 @@ enum TextClassTags {
bool LyXTextClass::Read(string const & filename, bool merge)
{
keyword_item textClassTags[] = {
{ "charstyle", TC_CHARSTYLE },
{ "classoptions", TC_CLASSOPTIONS },
{ "columns", TC_COLUMNS },
{ "counter", TC_COUNTER },
@ -346,6 +348,12 @@ bool LyXTextClass::Read(string const & filename, bool merge)
if (lexrc.next())
rightmargin_ = lexrc.getString();
break;
case TC_CHARSTYLE:
if (lexrc.next()) {
string const name = subst(lexrc.getString(), '_', ' ');
readCharStyle(lexrc, name);
}
break;
case TC_FLOAT:
readFloat(lexrc);
break;
@ -506,6 +514,85 @@ void LyXTextClass::readClassOptions(LyXLex & lexrc)
lexrc.popTable();
}
enum CharStyleTags {
CS_FONT = 1,
CS_LABELFONT,
CS_LATEXTYPE,
CS_LATEXNAME,
CS_PREAMBLE,
CS_END
};
void LyXTextClass::readCharStyle(LyXLex & lexrc, string const & name)
{
keyword_item elementTags[] = {
{ "end", CS_END },
{ "font", CS_FONT },
{ "labelfont", CS_LABELFONT },
{ "latexname", CS_LATEXNAME },
{ "latextype", CS_LATEXTYPE },
{ "preamble", CS_PREAMBLE}
};
lexrc.pushTable(elementTags, CS_END);
string latextype;
string latexname;
LyXFont font(LyXFont::ALL_INHERIT);
LyXFont labelfont(LyXFont::ALL_INHERIT);
string preamble;
bool getout = false;
while (!getout && lexrc.isOK()) {
int le = lexrc.lex();
switch (le) {
case LyXLex::LEX_UNDEF:
lexrc.printError("Unknown ClassOption tag `$$Token'");
continue;
default: break;
}
switch (static_cast<CharStyleTags>(le)) {
case CS_LATEXTYPE:
lexrc.next();
latextype = lexrc.getString();
break;
case CS_LATEXNAME:
lexrc.next();
latexname = lexrc.getString();
break;
case CS_LABELFONT:
labelfont.lyxRead(lexrc);
break;
case CS_FONT:
font.lyxRead(lexrc);
labelfont = font;
break;
case CS_PREAMBLE:
preamble = lexrc.getLongString("EndPreamble");
break;
case CS_END:
getout = true;
break;
}
}
//
// Here add element to list if getout == true
if (getout) {
CharStyle cs;
cs.name = name;
cs.latextype = latextype;
cs.latexname = latexname;
cs.font = font;
cs.labelfont = labelfont;
cs.preamble = preamble;
charstyles().push_back(cs);
}
lexrc.popTable();
}
enum FloatTags {
FT_TYPE = 1,
@ -519,6 +606,7 @@ enum FloatTags {
FT_END
};
void LyXTextClass::readFloat(LyXLex & lexrc)
{
keyword_item floatTags[] = {
@ -776,6 +864,18 @@ Counters & LyXTextClass::counters() const
}
CharStyles::iterator LyXTextClass::charstyle(string const & s) const
{
CharStyles::iterator cs = charstyles().begin();
CharStyles::iterator csend = charstyles().end();
for (; cs != csend; ++cs) {
if (cs->name == s)
return cs;
}
return csend;
}
string const & LyXTextClass::defaultLayoutName() const
{
// This really should come from the actual layout... (Lgb)

View File

@ -22,6 +22,21 @@ class Counters;
class FloatList;
///
struct CharStyle {
std::string name;
std::string latextype;
std::string latexname;
LyXFont font;
LyXFont labelfont;
std::string preamble;
};
/// List of semantically defined character style insets
typedef std::vector<CharStyle> CharStyles;
/// Stores the layout specification of a LyX document class.
class LyXTextClass {
public:
@ -55,6 +70,8 @@ public:
///
void readClassOptions(LyXLex &);
///
void readCharStyle(LyXLex &, std::string const &);
///
void readFloat(LyXLex &);
///
void readCounter(LyXLex &);
@ -73,6 +90,10 @@ public:
FloatList const & floats() const;
/// The Counters present in this document class.
Counters & counters() const;
/// CharStyles of this doc class
CharStyles & charstyles() const { return charstylelist_; };
/// Retrieve element of name s:
CharStyles::iterator charstyle(std::string const & s) const;
///
std::string const & defaultLayoutName() const;
///
@ -199,7 +220,9 @@ private:
/// Paragraph styles used in this layout
LayoutList layoutlist_;
/// CharStyles available to this layout
mutable CharStyles charstylelist_;
/// available types of float, eg. figure, algorithm.
boost::shared_ptr<FloatList> floatlist_;

View File

@ -1511,6 +1511,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
case LFUN_INSET_CAPTION:
#endif
case LFUN_INSERT_NOTE:
case LFUN_INSERT_CHARSTYLE:
case LFUN_INSERT_BOX:
case LFUN_INSERT_BRANCH:
case LFUN_INSERT_BIBITEM: