Here is a patch to make counter labels work again as they are supposed to in
Hebrew, i.e., right to left. At least I assume so, not knowing any Hebrew.
Please comment, especially if you do.

The enumerate labels are even hardwired for hebrew in counters.C; this code was
never used. With this patch, it is. And I extended the syntax of the layout
files to allow language dependence in label definitions.

At some point the enum definitions should also go to the layout files, but
perhaps not now.

As this fixes a regression connected to the introduction of the Counter classes
(I believe; I remember some Hebrew special casing was removed), I think this
should go in.

- Martin
Index: src/buffer_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer_funcs.C,v
retrieving revision 1.31
diff -u -p -r1.31 buffer_funcs.C
--- src/buffer_funcs.C	9 Jun 2005 09:58:05 -0000	1.31
+++ src/buffer_funcs.C	7 Aug 2005 08:33:02 -0000
@@ -23,6 +23,7 @@
 #include "Floating.h"
 #include "FloatList.h"
 #include "gettext.h"
+#include "language.h"
 #include "LaTeX.h"
 #include "lyxtextclass.h"
 #include "paragraph.h"
@@ -440,7 +441,8 @@ void setCounter(Buffer const & buf, ParI
 
 		counters.step(enumcounter);
 
-		par.params().labelString(counters.enumLabel(enumcounter));
+		par.params().labelString(counters.enumLabel(enumcounter,
+			par.getParLanguage(bufparams)->lang()));
 	} else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
 		counters.step("bibitem");
 		int number = counters.value("bibitem");
@@ -522,7 +524,8 @@ string expandLabel(Buffer const & buf,
 		}
 	}
 
-	return tclass.counters().counterLabel(fmt);
+	// Label format may depend on buffer language (hebrew!)
+	return tclass.counters().counterLabel(fmt, buf.params().language->lang());
 }
 
 
Index: src/counters.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/counters.C,v
retrieving revision 1.34
diff -u -p -r1.34 counters.C
--- src/counters.C	6 Jan 2005 16:39:22 -0000	1.34
+++ src/counters.C	7 Aug 2005 08:33:02 -0000
@@ -286,7 +286,7 @@ string Counters::labelItem(string const 
 }
 
 
-string Counters::counterLabel(string const & format)
+string Counters::counterLabel(string const & format, string const & language)
 {
 	string label = format;
 	while (true) {
@@ -294,7 +294,9 @@ string Counters::counterLabel(string con
 #warning Using boost::regex or boost::spirit would make this code a lot simpler... (Lgb)
 #endif
 
-		size_t const i = label.find('\\', 0);
+		size_t i = label.find('\\', 0);
+		while (i != string::npos && label.substr(i, 3) == "\\if")
+			i = label.find('\\', i + 1);
 		if (i == string::npos)
 			break;
 		size_t const j = label.find('{', i + 1);
@@ -311,15 +313,38 @@ string Counters::counterLabel(string con
 		//	<< numbertype << ") -> " << label << endl;
 	}
 	//lyxerr << "counterLabel: " << format  << " -> "	<< label << endl;
+	while (true) {
+	    	// To allow recursion. There may not be any other
+		// backslashes left in the string than "\if".
+		size_t const i = label.find_last_of('\\', 0);
+		if (i == string::npos)
+			break;
+		size_t const j = label.find('{', i + 3);
+		if (j == string::npos)
+			break;
+		size_t const m = label.find("}{", j + 1);
+		if (m == string::npos)
+			break;
+		size_t const k = label.find('}', m + 1);
+		if (k == string::npos)
+			break;
+		string const lang(label, i + 3, j - i - 3);
+		string const ifyes(label, j + 1, m - j - 1);
+		string const ifno(label, m + 2, k - m - 2);
+		string const rep(language == lang ? ifyes : ifno);
+		label = string(label, 0, i) + rep + string(label, k + 1, string::npos);
+	}
+
+	
 	return label;
 }
 
 
-string Counters::enumLabel(string const & ctr, string const & langtype)
+string Counters::enumLabel(string const & ctr, string const & language)
 {
 	ostringstream os;
 
-	if (langtype == "hebrew") {
+	if (language == "hebrew") {
 		if (ctr == "enumi")
 			os << '.' << value("enumi");
 		else if (ctr == "enumii")
Index: src/counters.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/counters.h,v
retrieving revision 1.17
diff -u -p -r1.17 counters.h
--- src/counters.h	6 Oct 2003 15:42:13 -0000	1.17
+++ src/counters.h	7 Aug 2005 08:33:02 -0000
@@ -76,9 +76,11 @@ public:
 	void copy(Counters & from, Counters & to, std::string const & match = std::string());
 	/// A complete expanded label, like 2.1.4 for a subsubsection
 	/// according to the given format
-	std::string counterLabel(std::string const & format);
+	std::string counterLabel(std::string const & format, 
+		std::string const & language);
 	/// A complete label, like 1.a for enumerations
-	std::string enumLabel(std::string const & ctr, std::string const & langtype = "latin");
+	std::string enumLabel(std::string const & ctr, 
+		std::string const & language);
 private:
 	/// A counter label's single item, 1 for subsection number in
 	/// the 2.1.4 subsubsection number label.
Index: lib/layouts/numarticle.inc
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/layouts/numarticle.inc,v
retrieving revision 1.4
diff -u -p -r1.4 numarticle.inc
--- lib/layouts/numarticle.inc	19 Apr 2005 09:00:32 -0000	1.4
+++ lib/layouts/numarticle.inc	7 Aug 2005 08:33:02 -0000
@@ -21,8 +21,8 @@ End
 Style Subsection
 	LabelType             Counter
 	LabelCounter          subsection
-	LabelString           "@[EMAIL PROTECTED]"
-	LabelStringAppendix   "@[EMAIL PROTECTED]"
+	LabelString           "[EMAIL PROTECTED]@[EMAIL PROTECTED]@.\arabic{subsection}}"
+	LabelStringAppendix   "[EMAIL PROTECTED]@[EMAIL PROTECTED]@.\arabic{subsection}}"
 	TocLevel              2
 End
 
@@ -30,8 +30,8 @@ End
 Style Subsubsection
 	LabelType             Counter
 	LabelCounter          subsubsection
-	LabelString           "@[EMAIL PROTECTED]"
-	LabelStringAppendix   "@[EMAIL PROTECTED]"
+	LabelString           "[EMAIL PROTECTED]@[EMAIL PROTECTED]@.\arabic{subsubsection}}"
+	LabelStringAppendix   "[EMAIL PROTECTED]@[EMAIL PROTECTED]@.\arabic{subsubsection}}"
 	TocLevel              3
 End
 
@@ -39,8 +39,8 @@ End
 Style Paragraph
 	LabelType             Counter
 	LabelCounter          paragraph
-	LabelString           "@[EMAIL PROTECTED]"
-	LabelStringAppendix   "@[EMAIL PROTECTED]"
+	LabelString           "[EMAIL PROTECTED]@[EMAIL PROTECTED]"
+	LabelStringAppendix   "[EMAIL PROTECTED]@[EMAIL PROTECTED]"
 	TocLevel              4
 End
 
@@ -48,7 +48,7 @@ End
 Style Subparagraph
 	LabelType             Counter
 	LabelCounter          subparagraph
-	LabelString           "@[EMAIL PROTECTED]"
-	LabelStringAppendix   "@[EMAIL PROTECTED]"
+	LabelString           "[EMAIL PROTECTED]@[EMAIL PROTECTED]@.\arabic{subparagraph}}"
+	LabelStringAppendix   "[EMAIL PROTECTED]@[EMAIL PROTECTED]@.\arabic{subparagraph}}"
 	TocLevel              5
 End
Index: lib/layouts/numreport.inc
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/layouts/numreport.inc,v
retrieving revision 1.4
diff -u -p -r1.4 numreport.inc
--- lib/layouts/numreport.inc	19 Apr 2005 09:00:32 -0000	1.4
+++ lib/layouts/numreport.inc	7 Aug 2005 08:33:02 -0000
@@ -18,7 +18,7 @@ End
 
 
 Style Section
-	LabelString           "\arabic{chapter}.\arabic{section}"
-	LabelStringAppendix   "\Alph{chapter}.\arabic{section}"
+	LabelString           "\ifhebrew{\arabic{section}.\arabic{chapter}}{\arabic{chapter}.\arabic{section}}"
+	LabelStringAppendix   "\ifhebrew{\arabic{section}.\Alph{chapter}}{\Alph{chapter}.\arabic{section}}"
 End
 

Reply via email to