fantasdic r377 - in trunk: . lib/fantasdic/sources lib/fantasdic/ui
- From: mblondel svn gnome org
- To: svn-commits-list gnome org
- Subject: fantasdic r377 - in trunk: . lib/fantasdic/sources lib/fantasdic/ui
- Date: Tue, 6 Jan 2009 00:46:10 +0000 (UTC)
Author: mblondel
Date: Tue Jan 6 00:46:10 2009
New Revision: 377
URL: http://svn.gnome.org/viewvc/fantasdic?rev=377&view=rev
Log:
* lib/fantasdic/sources/stardict_file.rb: Added xdxf markup support.
* lib/fantasdic/ui/utils.rb (TextBuffer#insert_pango_markup): Don't need
to set a Gtk::TextMark.
Modified:
trunk/ChangeLog
trunk/lib/fantasdic/sources/stardict_file.rb
trunk/lib/fantasdic/ui/utils.rb
Modified: trunk/lib/fantasdic/sources/stardict_file.rb
==============================================================================
--- trunk/lib/fantasdic/sources/stardict_file.rb (original)
+++ trunk/lib/fantasdic/sources/stardict_file.rb Tue Jan 6 00:46:10 2009
@@ -24,6 +24,22 @@
File.open(file_path) { |f| parse(f) }
end
+ def xdxf?
+ if has_key? "sametypesequence" and self["sametypesequence"] == "x"
+ true
+ else
+ false
+ end
+ end
+
+ def pango_markup?
+ if has_key? "sametypesequence" and self["sametypesequence"] == "g"
+ true
+ else
+ false
+ end
+ end
+
private
def parse(f)
@@ -206,7 +222,7 @@
n_errors = 0
n_lines = 0
- stardict_file_open do |index_file, dict_file|
+ stardict_file_open do |index_file, dict_file, file_info|
index_file.get_index_offsets.each do |offset|
n_errors += 1 if not offset.is_a? Fixnum
n_lines += 1
@@ -227,11 +243,12 @@
db = File.basename(@config[:filename]).slice(0...-6)
db_capitalize = db.capitalize
- stardict_file_open do |index_file, dict_file|
+ stardict_file_open do |index_file, dict_file, file_info|
index_file.match_exact(word).map do |match, offset, len|
defi = Definition.new
defi.word = match
defi.body = get_definition(dict_file, offset, len).strip
+ xdxf_to_pangomarkup!(defi.body) if file_info.xdxf?
defi.database = db
defi.description = db_capitalize
defi
@@ -242,7 +259,7 @@
def match(db, strat, word)
matches = []
- stardict_file_open do |index_file, dict_file|
+ stardict_file_open do |index_file, dict_file, file_info|
matches = case strat
when "prefix", "suffix", "substring", "word"
index_file.send("match_#{strat}", word)
@@ -292,16 +309,52 @@
end
index_file = StardictIndex.new(idx_file)
+ file_info = StardictInfo.new(@config[:filename])
if block_given?
- ret = yield(index_file, dict_file)
+ ret = yield(index_file, dict_file, file_info)
index_file.close
dict_file.close
ret
else
- [index_file, dict_file]
+ [index_file, dict_file, file_info]
+ end
+ end
+
+ XDXF_TO_PANGOMARKUP = [["<k>", "<b>"],
+ ["</k>", "</b>"],
+ ["<c c=", "<span color="],
+ ["</c>", "</span>"],
+ ["<kref>", "{"],
+ ["</kref>", "}"],
+ ["<abr>", ""],
+ ["</abr>", ""],
+ ["<pos>", "<small><i>"],
+ ["</pos>", "</i></small>"],
+ ["<blockquote>", "<i>"],
+ ["</blockquote>", "</i>"],
+ ["<opt>", "<span color=\"grey\">"],
+ ["</opt>", "</span>"],
+ ["<nu>", ""],
+ ["</nu>", ""],
+ ["<def>", ""],
+ ["</def>", ""],
+ ["<tense>", "<i>"],
+ ["</tense>", "</i><"],
+ ["<tr>", "<i>"],
+ ["</tr>", "</i>"],
+ ["<dtrn>", "<i>"],
+ ["</dtrn>", "</i>"],
+ ["<ex>", "<span color=\"grey\">"],
+ ["</ex>", "</span>"],
+ ["<co>", "<span color=\"blue\">"],
+ ["</co>", "</span>"]]
+
+ def xdxf_to_pangomarkup!(txt)
+ XDXF_TO_PANGOMARKUP.each do |from, to|
+ txt.gsub!(from, to)
end
end
Modified: trunk/lib/fantasdic/ui/utils.rb
==============================================================================
--- trunk/lib/fantasdic/ui/utils.rb (original)
+++ trunk/lib/fantasdic/ui/utils.rb Tue Jan 6 00:46:10 2009
@@ -187,7 +187,7 @@
end
# create_mark(name, iter, left= true or right=false)
- mark = create_mark(nil, iter, false)
+ # mark = create_mark(nil, iter, false)
paiter = attr_list.iterator
@@ -221,11 +221,11 @@
insert_with_tags(iter, text.slice(start...end_), *tags)
- iter = get_iter_at_mark(mark)
+ #iter = get_iter_at_mark(mark)
end while paiter.next!
- delete_mark(mark)
+ # delete_mark(mark)
end
end
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]